Add Python API examples for Supertonic TTS#3264
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a Python API example for Supertonic TTS, along with a corresponding test script. The changes are mostly good, but I've found a critical issue in the test script that would cause it to fail, and a couple of medium-severity issues related to maintainability and logging best practices. My review includes a fix for an incorrect file path in the test script, a suggestion to refactor hardcoded model paths in the Python example for better maintainability, and a correction to use the appropriate log level for a debug message in the C++ implementation.
| tar xvf sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2 | ||
| rm sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2 | ||
|
|
||
| python3 ./supertonic-tts.py |
There was a problem hiding this comment.
| def create_tts(): | ||
| tts_config = sherpa_onnx.OfflineTtsConfig( | ||
| model=sherpa_onnx.OfflineTtsModelConfig( | ||
| supertonic=sherpa_onnx.OfflineTtsSupertonicModelConfig( | ||
| duration_predictor="./sherpa-onnx-supertonic-tts-int8-2026-03-06/duration_predictor.int8.onnx", | ||
| text_encoder="./sherpa-onnx-supertonic-tts-int8-2026-03-06/text_encoder.int8.onnx", | ||
| vector_estimator="./sherpa-onnx-supertonic-tts-int8-2026-03-06/vector_estimator.int8.onnx", | ||
| vocoder="./sherpa-onnx-supertonic-tts-int8-2026-03-06/vocoder.int8.onnx", | ||
| tts_json="./sherpa-onnx-supertonic-tts-int8-2026-03-06/tts.json", | ||
| unicode_indexer="./sherpa-onnx-supertonic-tts-int8-2026-03-06/unicode_indexer.bin", | ||
| voice_style="./sherpa-onnx-supertonic-tts-int8-2026-03-06/voice.bin", | ||
| ), |
There was a problem hiding this comment.
The model directory path is hardcoded in multiple places. To improve maintainability and make it easier to update the model version in the future, it's better to define the model directory in a variable and use f-strings to construct the file paths.
| def create_tts(): | |
| tts_config = sherpa_onnx.OfflineTtsConfig( | |
| model=sherpa_onnx.OfflineTtsModelConfig( | |
| supertonic=sherpa_onnx.OfflineTtsSupertonicModelConfig( | |
| duration_predictor="./sherpa-onnx-supertonic-tts-int8-2026-03-06/duration_predictor.int8.onnx", | |
| text_encoder="./sherpa-onnx-supertonic-tts-int8-2026-03-06/text_encoder.int8.onnx", | |
| vector_estimator="./sherpa-onnx-supertonic-tts-int8-2026-03-06/vector_estimator.int8.onnx", | |
| vocoder="./sherpa-onnx-supertonic-tts-int8-2026-03-06/vocoder.int8.onnx", | |
| tts_json="./sherpa-onnx-supertonic-tts-int8-2026-03-06/tts.json", | |
| unicode_indexer="./sherpa-onnx-supertonic-tts-int8-2026-03-06/unicode_indexer.bin", | |
| voice_style="./sherpa-onnx-supertonic-tts-int8-2026-03-06/voice.bin", | |
| ), | |
| def create_tts(): | |
| model_dir = "sherpa-onnx-supertonic-tts-int8-2026-03-06" | |
| tts_config = sherpa_onnx.OfflineTtsConfig( | |
| model=sherpa_onnx.OfflineTtsModelConfig( | |
| supertonic=sherpa_onnx.OfflineTtsSupertonicModelConfig( | |
| duration_predictor=f"./{model_dir}/duration_predictor.int8.onnx", | |
| text_encoder=f"./{model_dir}/text_encoder.int8.onnx", | |
| vector_estimator=f"./{model_dir}/vector_estimator.int8.onnx", | |
| vocoder=f"./{model_dir}/vocoder.int8.onnx", | |
| tts_json=f"./{model_dir}/tts.json", | |
| unicode_indexer=f"./{model_dir}/unicode_indexer.bin", | |
| voice_style=f"./{model_dir}/voice.bin", | |
| ), |
| if (config_.model.debug) { | ||
| SHERPA_ONNX_LOGE("Number of speakers: %d", num_speakers_); | ||
| } |
There was a problem hiding this comment.
Using SHERPA_ONNX_LOGE for a debug message is misleading, as LOGE implies an error-level message. For debug information, it's better to use a logging level appropriate for debugging, such as SHERPA_ONNX_LOG(DEBUG). This improves clarity and allows for more granular control over log verbosity.
if (config_.model.debug) {
SHERPA_ONNX_LOG(DEBUG) << "Number of speakers: " << num_speakers_;
}There was a problem hiding this comment.
Pull request overview
Adds Python example usage and CI coverage for Supertonic TTS, plus minor internal logging and API exposure updates.
Changes:
- Export
OfflineTtsSupertonicModelConfigin the Python package API. - Add a runnable Python example demonstrating Supertonic TTS generation.
- Extend CI script to download the Supertonic model and run the example, storing output wavs.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sherpa-onnx/python/sherpa_onnx/init.py | Exposes Supertonic TTS model config from the Python package. |
| sherpa-onnx/csrc/offline-tts-supertonic-impl.cc | Adds debug logging for speaker count during voice style init. |
| python-api-examples/supertonic-tts.py | New end-to-end Python example for Supertonic TTS. |
| .gitignore | Ignores the downloaded Supertonic TTS model directory. |
| .github/scripts/test-python.sh | Runs the new Supertonic TTS Python example in CI and collects output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| full_style_ = std::move(style); | ||
|
|
||
| if (config_.model.debug) { | ||
| SHERPA_ONNX_LOGE("Number of speakers: %d", num_speakers_); |
There was a problem hiding this comment.
SHERPA_ONNX_LOGE logs at error level, but this message is emitted only when debug is enabled and isn’t an error condition. Consider switching to an info/debug-level macro (e.g., SHERPA_ONNX_LOGI/SHERPA_ONNX_LOGD) so debug runs don’t incorrectly surface errors in logs/CI.
| SHERPA_ONNX_LOGE("Number of speakers: %d", num_speakers_); | |
| SHERPA_ONNX_LOGD("Number of speakers: %d", num_speakers_); |
| end = time.time() | ||
|
|
||
| if len(audio.samples) == 0: | ||
| print("Error in generating audios. Please read previous error messages.") |
There was a problem hiding this comment.
The wording is grammatically off here; “audio” is typically uncountable in this context. Consider changing “audios” to “audio”.
| print("Error in generating audios. Please read previous error messages.") | |
| print("Error in generating audio. Please read previous error messages.") |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis change introduces support for Supertonic TTS integration by adding a new Python example script demonstrating TTS API usage, updating the test workflow to validate Supertonic functionality, exporting the model configuration, adding debug logging, and updating .gitignore for the prebuilt model artifact. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
cc @Wasser1462 @rodrigomatta
Summary by CodeRabbit
New Features
Tests