Skip to content

## 🔥 Feature: External API for Audiobook Generation #19

Merged
Blaizzy merged 14 commits intoBlaizzy:mainfrom
sergenes:external_script_support
Mar 17, 2025
Merged

## 🔥 Feature: External API for Audiobook Generation #19
Blaizzy merged 14 commits intoBlaizzy:mainfrom
sergenes:external_script_support

Conversation

@sergenes
Copy link
Copy Markdown
Contributor

@sergenes sergenes commented Mar 8, 2025

Summary

This PR introduces generate_audio(), a new function to allow external scripts to generate speech audio using mlx_audio for audiobook projects.

Changes

✅ Exposes generate_audio() for direct function calls outside the library.
✅ Supports multiple audio formats (wav, flac, etc.).
✅ Allows external scripts to generate audiobook chapters with custom voices, speed, and language codes.
✅ Includes a verbose flag to control logging output.

--
✅ Added from_cli flag: a simple way to handle CLI vs. script execution differences. This ensures that CLI-generated files get the _000 suffix as expected, while script-based calls save files without a suffix (e.g., audiobook_chapter1.wav).

Usage Example

External projects can now generate audiobooks like this:

from mlx_audio.tts.generate import generate_audio

generate_audio(
    text="Once upon a time...",
    file_path="audiobook_intro",
    audio_format="flac"
)

Why This PR?
This change makes it easier to integrate mlx_audio into audiobook generation projects, showcasing its potential for text-to-speech applications.

I'm going to use it for my experiments here:
https://github.com/sergenes/runandread-audiobook

But I'm pretty sure it will be useful to others as well!

🔥🔥🔥 I love this repo! Thank you for your work! 🚀👏

@Blaizzy
Copy link
Copy Markdown
Owner

Blaizzy commented Mar 8, 2025

Thanks for the great contribution @sergenes!

I left one comment.

@Blaizzy Blaizzy self-requested a review March 15, 2025 19:32
@Blaizzy
Copy link
Copy Markdown
Owner

Blaizzy commented Mar 15, 2025

Made some small changes.

Could you please run before we merge:

pre-commit run --all

@sergenes
Copy link
Copy Markdown
Contributor Author

Made some small changes.

Could you please run before we merge:

pre-commit run --all

Done!

@sergenes
Copy link
Copy Markdown
Contributor Author

Let me know if you'd like me to rebase the branch!

@Blaizzy
Copy link
Copy Markdown
Owner

Blaizzy commented Mar 16, 2025

Yes, that would be great.

Please do rebase :)

@sergenes
Copy link
Copy Markdown
Contributor Author

Yes, that would be great.

Please do rebase :)

I was busy with the kids over the weekend. I'll try to find some time at the beginning of next week!

@Blaizzy
Copy link
Copy Markdown
Owner

Blaizzy commented Mar 16, 2025

No worries, ping me when you do :)

@sergenes
Copy link
Copy Markdown
Contributor Author

No worries, ping me when you do :)

Done!
Re-rebased with the main branch and restored all features.

I tested both options a bit. Please merge to avoid needing to rebase again! :)

@sergenes
Copy link
Copy Markdown
Contributor Author

Hmm, it looks like merging is blocked because you pushed to this branch once. What should we do?

@sergenes
Copy link
Copy Markdown
Contributor Author

I can make a new Pull Request..

@sergenes
Copy link
Copy Markdown
Contributor Author

New PR: #42

@Blaizzy
Copy link
Copy Markdown
Owner

Blaizzy commented Mar 17, 2025

@sergenes no need for a new PR, I made the necessary changes and it's ready to be merged :)

@sergenes
Copy link
Copy Markdown
Contributor Author

thank you!

@Blaizzy Blaizzy merged commit 47dc0bb into Blaizzy:main Mar 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants