Add JavaScript API examples for Supertonic3 TTS (#3614)

This commit is contained in:
Fangjun Kuang authored and GitHub committed 2026-05-14 11:14:25 +08:00
1 parent 13d0ae6c53
commit c910efa342
3 files changed
+119

No files matched your search

+8
View File
@@ -103,6 +103,14 @@ node ./test-offline-tts-kitten-en.js
ls -lh *.wav
rm -rf kitten-nano-en-v0_1-fp16
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/sherpa-onnx-supertonic-3-tts-int8-2026-05-11.tar.bz2
tar xf sherpa-onnx-supertonic-3-tts-int8-2026-05-11.tar.bz2
rm sherpa-onnx-supertonic-3-tts-int8-2026-05-11.tar.bz2
node ./test-offline-tts-supertonic.js
ls -lh *.wav
rm -rf sherpa-onnx-supertonic-3-tts-int8-2026-05-11
# online asr
curl -LS -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-paraformer-bilingual-zh-en.tar.bz2
tar xvf sherpa-onnx-streaming-paraformer-bilingual-zh-en.tar.bz2
+31
View File
@@ -124,6 +124,21 @@ curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/vocoder-mode
node ./test-offline-tts-zipvoice-zh-en.js
```
## ./test-offline-tts-supertonic.js
[./test-offline-tts-supertonic.js](./test-offline-tts-supertonic.js)
shows how to use SupertonicTTS 3 for text-to-speech.
It supports 31 languages. The example demonstrates English, Japanese, and German.
You can use the following command to run it:
```bash
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/sherpa-onnx-supertonic-3-tts-int8-2026-05-11.tar.bz2
tar xf sherpa-onnx-supertonic-3-tts-int8-2026-05-11.tar.bz2
rm sherpa-onnx-supertonic-3-tts-int8-2026-05-11.tar.bz2
node ./test-offline-tts-supertonic.js
```
## ./test-offline-tts-pocket-en.js
[./test-offline-tts-pocket-en.js](./test-offline-tts-pocket-en.js)
@@ -170,6 +185,22 @@ rm kokoro-en-v0_19.tar.bz2
node ./test-offline-tts-kokoro-en.js
```
## ./test-offline-tts-kokoro-zh-en.js
[./test-offline-tts-kokoro-zh-en.js](./test-offline-tts-kokoro-zh-en.js) shows how to use
[kokoro-multi-lang-v1_0](https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kokoro-multi-lang-v1_0.tar.bz2)
for text-to-speech in Chinese and English.
You can use the following command to run it:
```bash
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kokoro-multi-lang-v1_0.tar.bz2
tar xf kokoro-multi-lang-v1_0.tar.bz2
rm kokoro-multi-lang-v1_0.tar.bz2
node ./test-offline-tts-kokoro-zh-en.js
```
## ./test-offline-tts-matcha-zh.js
[./test-offline-tts-matcha-zh.js](./test-offline-tts-matcha-zh.js) shows how to use
@@ -0,0 +1,80 @@
// Copyright (c) 2026 Xiaomi Corporation (authors: Fangjun Kuang)
const sherpa_onnx = require('sherpa-onnx');
// please refer to
// https://k2-fsa.github.io/sherpa/onnx/tts/supertonic.html
// to download model files
function createOfflineTts() {
let supertonic = {
durationPredictor:
'./sherpa-onnx-supertonic-3-tts-int8-2026-05-11/duration_predictor.int8.onnx',
textEncoder:
'./sherpa-onnx-supertonic-3-tts-int8-2026-05-11/text_encoder.int8.onnx',
vectorEstimator:
'./sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vector_estimator.int8.onnx',
vocoder: './sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vocoder.int8.onnx',
ttsJson: './sherpa-onnx-supertonic-3-tts-int8-2026-05-11/tts.json',
unicodeIndexer:
'./sherpa-onnx-supertonic-3-tts-int8-2026-05-11/unicode_indexer.bin',
voiceStyle: './sherpa-onnx-supertonic-3-tts-int8-2026-05-11/voice.bin',
};
let offlineTtsModelConfig = {
offlineTtsSupertonicModelConfig: supertonic,
numThreads: 1,
debug: 1,
provider: 'cpu',
};
let offlineTtsConfig = {
offlineTtsModelConfig: offlineTtsModelConfig,
maxNumSentences: 1,
};
return sherpa_onnx.createOfflineTts(offlineTtsConfig);
}
const tts = createOfflineTts();
const speakerId = 0; // it has 10 speakers, valid speakerId [0,9]
const speed = 1.0;
const numSteps = 8;
// SupertonicTTS supports 31 languages. Use --lang to select one.
// Supported language codes:
// ar, bg, cs, da, de, el, en, es, et, fi, fr, hi, hr, hu,
// id, it, ja, ko, lt, lv, nl, pl, pt, ro, ru, sk, sl, sv,
// tr, uk, vi
//
// See also https://k2-fsa.github.io/sherpa/onnx/tts/supertonic.html
const samples = [
{
lang: 'en',
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.',
},
{
lang: 'ja',
text: 'これは次世代のkaldiを使用したテキスト読み上げエンジンです。',
},
{
lang: 'de',
text: 'Alles hat ein Ende, nur die Wurst hat zwei.',
},
];
for (const s of samples) {
const generationConfig = {
sid: speakerId,
speed: speed,
numSteps: numSteps,
extra: {lang: s.lang},
};
const audio = tts.generateWithConfig(s.text, generationConfig);
const filename = `./test-supertonic-${s.lang}.wav`;
tts.save(filename, audio);
console.log(`Saved to ${filename} successfully.`);
}
tts.free();