Add ability to use a custom URL to load Kokoro safetensors
Context
Currently kokoro.safetensors need to be added to the bundle, not optimal since it's 300MB, this need to be more flexible to facilitate the use of the package outside of the provided .xcodeproj.
Description
Adding a way to pass an URL of the .safetensors by adding the customURL parameters to the KokoroTTS class.
Changes in the codebase
Mainly modifying KokoroTTS init and KokoroWeightLoader loadWeights() func passing an optional URL.
Changes outside the codebase
None.
Additional information
None.
Hey @adrgrondin
Thank you very much for this awesome contribution!
What do you think if we add support for downloading model info from huggingface using swift-transformers?
Since we now support more models such as Orpheus.
Hey @adrgrondin
Thank you very much for this awesome contribution!
What do you think if we add support for downloading model info from huggingface using swift-transformers?
Since we now support more models such as Orpheus.
Thank @Blaizzy!
This PR is a first step for that! The model can be downloaded with swift-transformers and then passed to KokoroTTS init when used outside this xcodeproj. That said adding swift-transformers here requires more work depending on the goal (only adding to the xcodeproj for the showcase app? Also adding to the package with a public API?) but definitely is an option that would make things better and easier as more models are added.
I can work first on adding the customURL too for Orpheus in another PR and when I have time explore the possibilities for swift-transformers.
@Blaizzy any way to relaunch the tests? They passed on my side but seems to be looped on CI.
Sounds good!
Please add the custom url to Orpheus too
Sounds good!
Please add the custom url to Orpheus too
@Blaizzy I added 2 more commits, one to pass the custom URL for Orpheus and one to handle errors the same way in both weight loader utility classes (small refactoring of KokoroWeightLoader to handle error the same way OrpheusWeightLoader does, a bit nicer).
Also changed indentation since the code was indented with 2 spaces compared to the default 4 (other files are untouched since they have the default 4).
Thanks @adrgrondin!
Sorry for the delay we have been busy on some work behind the scenes for mlx-audio.
No worries @Blaizzy ! I hope to be able to contribute more in the future.