Skip to content

Add Python API examples for Supertonic TTS#3264

Merged
csukuangfj merged 2 commits intok2-fsa:masterfrom
csukuangfj:python-api-example-supertonic-tts
Mar 6, 2026
Merged

Add Python API examples for Supertonic TTS#3264
csukuangfj merged 2 commits intok2-fsa:masterfrom
csukuangfj:python-api-example-supertonic-tts

Conversation

@csukuangfj
Copy link
Copy Markdown
Collaborator

@csukuangfj csukuangfj commented Mar 6, 2026

cc @Wasser1462 @rodrigomatta

Summary by CodeRabbit

  • New Features

    • Added Supertonic TTS support with a new Python example demonstrating text-to-speech generation.
    • Made OfflineTtsSupertonicModelConfig publicly available in the API.
  • Tests

    • Added test workflow for Supertonic TTS functionality.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 6, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 sherpa-onnx project by integrating a new Python API example for the Supertonic Text-to-Speech (TTS) model. The changes facilitate easier adoption and testing of Supertonic TTS capabilities, allowing users to generate speech from text using a dedicated Python script. It also includes necessary updates to the build and ignore configurations to support this new example.

Highlights

  • New Python API Example: A new Python script, supertonic-tts.py, has been added to demonstrate the usage of the Supertonic Text-to-Speech (TTS) model within the sherpa-onnx library.
  • CI Integration: The continuous integration test script for Python examples has been updated to include the new Supertonic TTS example, ensuring its functionality is automatically verified.
  • Model Management: The .gitignore file was updated to prevent the Supertonic TTS model directory from being committed to the repository.
  • API Configuration Exposure: The OfflineTtsSupertonicModelConfig class has been explicitly imported in the sherpa_onnx Python package's __init__.py to make it accessible for users.
Changelog
  • .github/scripts/test-python.sh
    • Added a new test block for Supertonic TTS, including steps to download, extract, run the Python example, and clean up the model files.
    • Modified the mkdir ./tts command to mkdir -p ./tts for idempotent directory creation.
  • .gitignore
    • Appended sherpa-onnx-supertonic-tts-int8-2026-03-06 to the list of ignored files/directories.
  • python-api-examples/supertonic-tts.py
    • Created a new Python script that demonstrates how to initialize and use the sherpa_onnx.OfflineTts API with Supertonic TTS models, including configuration, text generation, and saving audio output.
  • sherpa-onnx/csrc/offline-tts-supertonic-impl.cc
    • Introduced a debug log message to print the number of speakers (num_speakers_) when the config_.model.debug flag is enabled.
  • sherpa-onnx/python/sherpa_onnx/init.py
    • Imported OfflineTtsSupertonicModelConfig to expose it in the top-level sherpa_onnx namespace.
Activity
  • No human activity (comments, reviews) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@csukuangfj csukuangfj requested a review from Copilot March 6, 2026 07:17
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/scripts/test-python.sh Outdated
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The path to the Python script is incorrect. The script supertonic-tts.py is located in the python-api-examples/ directory, but it's being called from the root. This will cause the test to fail.

Suggested change
python3 ./supertonic-tts.py
python3 python-api-examples/supertonic-tts.py

Comment on lines +33 to +44
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",
),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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",
),

Comment on lines +607 to +609
if (config_.model.debug) {
SHERPA_ONNX_LOGE("Number of speakers: %d", num_speakers_);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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_;
  }

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Python example usage and CI coverage for Supertonic TTS, plus minor internal logging and API exposure updates.

Changes:

  • Export OfflineTtsSupertonicModelConfig in 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_);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
SHERPA_ONNX_LOGE("Number of speakers: %d", num_speakers_);
SHERPA_ONNX_LOGD("Number of speakers: %d", num_speakers_);

Copilot uses AI. Check for mistakes.
end = time.time()

if len(audio.samples) == 0:
print("Error in generating audios. Please read previous error messages.")
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording is grammatically off here; “audio” is typically uncountable in this context. Consider changing “audios” to “audio”.

Suggested change
print("Error in generating audios. Please read previous error messages.")
print("Error in generating audio. Please read previous error messages.")

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 6, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9c0c4991-6813-4092-bf72-79f22ef58cc5

📥 Commits

Reviewing files that changed from the base of the PR and between b1f921f and 672163c.

📒 Files selected for processing (5)
  • .github/scripts/test-python.sh
  • .gitignore
  • python-api-examples/supertonic-tts.py
  • sherpa-onnx/csrc/offline-tts-supertonic-impl.cc
  • sherpa-onnx/python/sherpa_onnx/__init__.py

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Python API Example & Export
python-api-examples/supertonic-tts.py, sherpa-onnx/python/sherpa_onnx/__init__.py
New Python example script implementing create_tts() and main() functions for Supertonic TTS integration, with audio generation and WAV file output. Exports OfflineTtsSupertonicModelConfig in public API.
Test Infrastructure
.github/scripts/test-python.sh, .gitignore
Added test workflow for Supertonic TTS covering model download, extraction, and Python example execution. Added .gitignore pattern for prebuilt model artifact. Improved mkdir robustness with -p flag.
C++ Implementation
sherpa-onnx/csrc/offline-tts-supertonic-impl.cc
Added debug-only logging to print speaker count when debug mode is enabled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • k2-fsa/sherpa-onnx#2466: Parallel TTS model support addition with coordinated changes across test scripts, Python examples, and API exports.

Poem

🐰 Hop along with Supertonic sound,
Audio samples spinning 'round and 'round!
Tests now whisper, examples show the way,
Rabbits celebrate this TTS day! 🎵

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants