Files
sherpa-onnx/nodejs-examples/test-offline-tts-matcha-en-lexicon.js
Fangjun Kuang 0b3647632f Remove espeak-ng and piper-phonemize from sherpa-onnx (#4055)
Fixes #3731

espeak-ng and piper-phonemize are no longer built into sherpa-onnx.

Text frontends are now:

- **lexicon** — built in, no extra dependency
- **phonemize** — phonemize outside sherpa-onnx (e.g. [piper-phonemize](https://github.com/csukuangfj/piper-phonemize)) and pass the result in. That library is GPL, so it stays optional: sherpa-onnx is GPL-free after this PR.

## API

- `SherpaOnnxGenerationConfig` gains `phoneme_codepoints` and `tokens` (mutually exclusive alternatives to `text`)
- `data_dir` on the TTS model configs is deprecated and ignored; the ABI slot is kept
- all bindings updated: C/C++, Python, Java, Kotlin, Go, Rust, C#, Swift, Pascal, Dart/Flutter, node-addon, WASM, HarmonyOS
2026-10-20 11:09:04 +08:00

47 lines
1.3 KiB
JavaScript

// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
const sherpa_onnx = require('sherpa-onnx');
const silenceScale = 0.2;
function createOfflineTts() {
let offlineTtsMatchaModelConfig = {
acousticModel: './matcha-icefall-en_US-ljspeech/model-steps-3.onnx',
vocoder: './vocos-22khz-univ.onnx',
lexicon: './lexicon-en-us.txt',
tokens: './matcha-icefall-en_US-ljspeech/tokens.txt',
noiseScale: 0.667,
lengthScale: 1.0,
};
let offlineTtsModelConfig = {
offlineTtsMatchaModelConfig: offlineTtsMatchaModelConfig,
numThreads: 1,
debug: 1,
provider: 'cpu',
};
let offlineTtsConfig = {
offlineTtsModelConfig: offlineTtsModelConfig,
maxNumSentences: 1,
silenceScale: silenceScale,
};
return sherpa_onnx.createOfflineTts(offlineTtsConfig);
}
const tts = createOfflineTts();
const 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.';
const generationConfig = {
sid: 0,
speed: 1.0,
silenceScale: silenceScale,
};
const audio = tts.generateWithConfig(text, generationConfig);
tts.save('./test-matcha-en-lexicon.wav', audio);
console.log('Saved to test-matcha-en-lexicon.wav successfully.');
tts.free();