mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-11-10 13:04:05 +08:00
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
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
|
|
|
|
const sherpa_onnx = require('sherpa-onnx');
|
|
|
|
function createOfflineTts() {
|
|
let offlineTtsKokoroModelConfig = {
|
|
model: './kokoro-multi-lang-v1_0/model.onnx',
|
|
voices: './kokoro-multi-lang-v1_0/voices.bin',
|
|
tokens: './kokoro-multi-lang-v1_0/tokens.txt',
|
|
lexicon:
|
|
'./kokoro-multi-lang-v1_0/lexicon-us-en.txt,./kokoro-multi-lang-v1_0/lexicon-zh.txt',
|
|
lengthScale: 1.0,
|
|
};
|
|
let offlineTtsModelConfig = {
|
|
offlineTtsKokoroModelConfig: offlineTtsKokoroModelConfig,
|
|
numThreads: 1,
|
|
debug: 1,
|
|
provider: 'cpu',
|
|
};
|
|
|
|
let offlineTtsConfig = {
|
|
offlineTtsModelConfig: offlineTtsModelConfig,
|
|
maxNumSentences: 1,
|
|
};
|
|
|
|
return sherpa_onnx.createOfflineTts(offlineTtsConfig);
|
|
}
|
|
|
|
const tts = createOfflineTts();
|
|
const speakerId = 49;
|
|
const speed = 1.0;
|
|
const generationConfig = {
|
|
sid: speakerId,
|
|
speed: speed,
|
|
silenceScale: 0.2,
|
|
};
|
|
const text =
|
|
'中英文语音合成测试。This is generated by next generation Kaldi using Kokoro without Misaki. 你觉得中英文说的如何呢?';
|
|
|
|
const audio = tts.generateWithConfig(text, generationConfig);
|
|
tts.save('./test-kokoro-zh-en-49-lexicon.wav', audio);
|
|
console.log('Saved to test-kokoro-zh-en-49-lexicon.wav successfully.');
|
|
tts.free();
|