-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Pascal API and example for Supertonic TTS. #3290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ kitten-en-playback | |
| kokoro-zh-en | ||
| kokoro-zh-en-playback | ||
| pocket-en | ||
| supertonic-en | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| set -ex | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||||||||||||||||||||||||
| SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd) | ||||||||||||||||||||||||
|
Comment on lines
+5
to
+6
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| echo "SHERPA_ONNX_DIR: $SHERPA_ONNX_DIR" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if [[ ! -f ../../build/install/lib/libsherpa-onnx-c-api.dylib && ! -f ../../build/install/lib/libsherpa-onnx-c-api.so && ! -f ../../build/install/lib/sherpa-onnx-c-api.dll ]]; then | ||||||||||||||||||||||||
| mkdir -p ../../build | ||||||||||||||||||||||||
| pushd ../../build | ||||||||||||||||||||||||
| cmake \ | ||||||||||||||||||||||||
| -DCMAKE_INSTALL_PREFIX=./install \ | ||||||||||||||||||||||||
| -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||||||||||||||||||||||||
| -DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||||||||||||||||||||||||
| -DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||||||||||||||||||||||||
| -DBUILD_SHARED_LIBS=ON \ | ||||||||||||||||||||||||
| -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||||||||||||||||||||||||
| .. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| cmake --build . --target install --config Release | ||||||||||||||||||||||||
| popd | ||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # please visit | ||||||||||||||||||||||||
| # https://k2-fsa.github.io/sherpa/onnx/tts/supertonic.html | ||||||||||||||||||||||||
| if [ ! -f ./sherpa-onnx-supertonic-tts-int8-2026-03-06/duration_predictor.int8.onnx ]; then | ||||||||||||||||||||||||
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2 | ||||||||||||||||||||||||
| tar xvf sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2 | ||||||||||||||||||||||||
| rm sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2 | ||||||||||||||||||||||||
|
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "run-supertonic-en.sh" -type fRepository: k2-fsa/sherpa-onnx Length of output: 108 🏁 Script executed: sed -n '29,31p' ./pascal-api-examples/tts/run-supertonic-en.shRepository: k2-fsa/sherpa-onnx Length of output: 310 🌐 Web query:
💡 Result:
Common “silent but fail on HTTP errors” pattern: curl -fsS https://example.com/resourceSources: [1] curl man page ( 🌐 Web query:
💡 Result:
So the key difference is: Harden model download: fail fast and bound network retries/timeouts. The current The proposed hardening adds:
🛡️ Proposed hardening- curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2
+ curl --fail --show-error --location \
+ --retry 3 --retry-delay 2 --connect-timeout 30 --max-time 1200 \
+ -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/sherpa-onnx-supertonic-tts-int8-2026-03-06.tar.bz2📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||
|
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The model name
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| fpc \ | ||||||||||||||||||||||||
| -dSHERPA_ONNX_USE_SHARED_LIBS \ | ||||||||||||||||||||||||
| -Fu$SHERPA_ONNX_DIR/sherpa-onnx/pascal-api \ | ||||||||||||||||||||||||
| -Fl$SHERPA_ONNX_DIR/build/install/lib \ | ||||||||||||||||||||||||
| ./supertonic-en.pas | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export LD_LIBRARY_PATH=$SHERPA_ONNX_DIR/build/install/lib:$LD_LIBRARY_PATH | ||||||||||||||||||||||||
| export DYLD_LIBRARY_PATH=$SHERPA_ONNX_DIR/build/install/lib:$DYLD_LIBRARY_PATH | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ./supertonic-en | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| { Copyright (c) 2026 Xiaomi Corporation } | ||
| program supertonic_en; | ||
| { | ||
| This file shows how to use the text to speech API of sherpa-onnx | ||
| with Supertonic TTS models. | ||
|
|
||
| It generates speech from text and saves it to a wave file. | ||
|
|
||
| Please visit | ||
| https://k2-fsa.github.io/sherpa/onnx/tts/supertonic.html | ||
| to download the model. | ||
| } | ||
|
|
||
| {$mode objfpc} | ||
|
|
||
| uses | ||
| SysUtils, | ||
| sherpa_onnx; | ||
|
|
||
| function GetOfflineTts: TSherpaOnnxOfflineTts; | ||
| var | ||
| Config: TSherpaOnnxOfflineTtsConfig; | ||
| begin | ||
| Config.Model.Supertonic.DurationPredictor := './sherpa-onnx-supertonic-tts-int8-2026-03-06/duration_predictor.int8.onnx'; | ||
| Config.Model.Supertonic.TextEncoder := './sherpa-onnx-supertonic-tts-int8-2026-03-06/text_encoder.int8.onnx'; | ||
| Config.Model.Supertonic.VectorEstimator := './sherpa-onnx-supertonic-tts-int8-2026-03-06/vector_estimator.int8.onnx'; | ||
| Config.Model.Supertonic.Vocoder := './sherpa-onnx-supertonic-tts-int8-2026-03-06/vocoder.int8.onnx'; | ||
| Config.Model.Supertonic.TtsJson := './sherpa-onnx-supertonic-tts-int8-2026-03-06/tts.json'; | ||
| Config.Model.Supertonic.UnicodeIndexer := './sherpa-onnx-supertonic-tts-int8-2026-03-06/unicode_indexer.bin'; | ||
| Config.Model.Supertonic.VoiceStyle := './sherpa-onnx-supertonic-tts-int8-2026-03-06/voice.bin'; | ||
| Config.Model.NumThreads := 2; | ||
| Config.Model.Debug := True; | ||
| Config.MaxNumSentences := 1; | ||
|
Comment on lines
+21
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The model directory path |
||
|
|
||
| Result := TSherpaOnnxOfflineTts.Create(Config); | ||
| end; | ||
|
|
||
| var | ||
| Tts: TSherpaOnnxOfflineTts; | ||
| GenerationConfig: TSherpaOnnxGenerationConfig; | ||
| Audio: TSherpaOnnxGeneratedAudio; | ||
| Text: AnsiString; | ||
|
|
||
| begin | ||
| Tts := GetOfflineTts; | ||
|
|
||
| WriteLn('There are ', Tts.GetNumSpeakers, ' speakers'); | ||
|
|
||
| Text := 'Today as always, men fall into two groups: slaves and free men. Whoever ' + | ||
| 'does not have two-thirds of his day for himself, is a slave, whatever ' + | ||
| 'he may be: a statesman, a businessman, an official, or a scholar.'; | ||
|
|
||
| GenerationConfig.Sid := 6; | ||
| GenerationConfig.NumSteps := 5; | ||
| GenerationConfig.Speed := 1.25; | ||
| GenerationConfig.Extra := '{"lang": "en"}'; | ||
|
|
||
| Audio := Tts.Generate(Text, GenerationConfig, NIL, NIL); | ||
| SherpaOnnxWriteWave('./supertonic-tts-en.wav', Audio.Samples, Audio.SampleRate); | ||
| WriteLn('Saved to ./supertonic-tts-en.wav'); | ||
|
|
||
| FreeAndNil(Tts); | ||
| end. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example script downloads and extracts a
sherpa-onnx-supertonic-tts-*model directory underpascal-api-examples/tts/. Consider ignoring that extracted directory pattern as well to reduce the chance of accidentally committing large model artifacts (similar to how other example assets are typically handled).