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
53 lines
1.6 KiB
Python
Executable File
53 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Test OfflineTtsVitsExtImpl with an inflect model using lexicon-based phonemization.
|
|
|
|
Download model and lexicon:
|
|
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-inflect-en-nano-v2.tar.bz2
|
|
tar xf vits-inflect-en-nano-v2.tar.bz2
|
|
|
|
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/lexicon-en-us.txt
|
|
"""
|
|
|
|
import time
|
|
|
|
import sherpa_onnx
|
|
import soundfile as sf
|
|
|
|
tts_config = sherpa_onnx.OfflineTtsConfig(
|
|
model=sherpa_onnx.OfflineTtsModelConfig(
|
|
vits=sherpa_onnx.OfflineTtsVitsModelConfig(
|
|
model="./vits-inflect-en-nano-v2/model.onnx",
|
|
tokens="./vits-inflect-en-nano-v2/tokens.txt",
|
|
lexicon="./lexicon-en-us.txt",
|
|
),
|
|
debug=True,
|
|
),
|
|
)
|
|
tts = sherpa_onnx.OfflineTts(tts_config)
|
|
|
|
text = "Friends fell out often because life was changing so fast."
|
|
|
|
gen_config = sherpa_onnx.GenerationConfig()
|
|
gen_config.sid = 0
|
|
gen_config.speed = 1.0
|
|
|
|
start = time.time()
|
|
audio = tts.generate(text, gen_config)
|
|
end = time.time()
|
|
|
|
assert len(audio.samples) > 0, "No audio generated!"
|
|
assert audio.sample_rate > 0, "Invalid sample rate!"
|
|
|
|
filename = "test-inflect-lexicon.wav"
|
|
sf.write(filename, audio.samples, samplerate=audio.sample_rate)
|
|
|
|
elapsed_seconds = end - start
|
|
audio_duration = len(audio.samples) / audio.sample_rate
|
|
rtf = elapsed_seconds / audio_duration
|
|
|
|
print(f"Saved to {filename}")
|
|
print(f"Elapsed seconds: {elapsed_seconds:.3f}")
|
|
print(f"Audio duration in seconds: {audio_duration:.3f}")
|
|
print(f"RTF: {elapsed_seconds:.3f}/{audio_duration:.3f} = {rtf:.3f}")
|