mlx-audio icon indicating copy to clipboard operation
mlx-audio copied to clipboard

Add ability to use a custom URL to load Kokoro safetensors

Open adrgrondin opened this issue 9 months ago • 5 comments

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.

adrgrondin avatar May 27 '25 21:05 adrgrondin

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.

Blaizzy avatar May 27 '25 21:05 Blaizzy

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.

adrgrondin avatar May 27 '25 22:05 adrgrondin

@Blaizzy any way to relaunch the tests? They passed on my side but seems to be looped on CI.

adrgrondin avatar May 28 '25 06:05 adrgrondin

Sounds good!

Please add the custom url to Orpheus too

Blaizzy avatar May 28 '25 09:05 Blaizzy

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).

adrgrondin avatar May 28 '25 20:05 adrgrondin

Thanks @adrgrondin!

Sorry for the delay we have been busy on some work behind the scenes for mlx-audio.

Blaizzy avatar Aug 03 '25 22:08 Blaizzy

No worries @Blaizzy ! I hope to be able to contribute more in the future.

adrgrondin avatar Aug 03 '25 23:08 adrgrondin