|
This version is still in development and is not considered stable yet. For the latest stable version, please use dengjen 3.x! |
Synthesizing speech
Dengjen synthesizes speech from a Piper voice. Download a
voice’s .onnx model and matching .onnx.json config from the
Piper voices repository and keep both files
together, e.g. voices/en_US-lessac-medium.onnx and voices/en_US-lessac-medium.onnx.json.
A voice doesn’t have to come from the official Piper voices repository — any VITS-family ONNX
export using the same 3/4-input tensor convention (phoneme ids, lengths, scales, optional
speaker id) can be loaded by writing a matching .onnx.json manifest with
"model_type": "vits". The minimal required fields are audio (sample rate), inference
(noise_scale/length_scale/noise_w), and phoneme_id_map (the symbol vocabulary);
phoneme_type selects the phonemizer (espeak is the default if omitted, and needs an
espeak.voice entry — text, hebrew, and pinyin don’t).
A MeloTTS voice — its own VITS-derived ONNX export, with
a tones tensor alongside phone ids — is loaded with "model_type": "melotts". The required
fields are audio (sample rate), inference
(noise_scale/length_scale/noise_scale_w), phone_id_map and tone_id_map (the phone and
tone symbol vocabularies), and model_path; phonemizer selects the phonemization backend and
must be one of {"type": "espeak", "voice": "<espeak-ng voice name>"} (covers English, Spanish,
French, Japanese, Korean) or {"type": "pinyin", "model_dir": "<g2pW model directory>"}
(Chinese, with real tone extraction — requires building with the pinyin feature).
CLI
Synthesize text from a file to a WAV file, using the dengjen CLI (crate dengjen-tts-cli).
The speak argument is a model config path or the key of an installed voice (see
Managing voices).
Synthesis moved to the speak subcommand. dengjen <config> no longer works; use
dengjen speak <config>.
|
cargo run --release -p dengjen-tts-cli -- speak voices/en_US-lessac-medium.onnx.json \
-f input.txt \
-o output.wav
Or send a single request as JSON on stdin and capture the WAV bytes written to stdout:
echo '{"text": "Hello world"}' | cargo run --release -p dengjen-tts-cli -- speak voices/en_US-lessac-medium.onnx.json > output.wav
Run dengjen speak --help (or cargo run --release -p dengjen-tts-cli — speak --help) for the full list
of options. The main ones:
-
--mode lazy|parallel|batched|realtimeselects the synthesis mode (defaultlazy).--batch-sizesets how many sentencesbatchedsynthesizes per concurrent group, and--chunk-sizeand--chunk-paddingtunerealtimechunking. -
--speaker-idpicks a speaker for multi-speaker voices; when omitted, the voice’s own default speaker from its manifest is used (Kokoro’s is0). -
--rate,--pitchand--volumetake 0-100. When omitted, each stays at 1.0 (no change). The value maps linearly onto a speed of 0.5x-5.5x (so 10 is 1x and 50 is 3x), a pitch of 0.5-1.5 and a volume gain of 0-1 (a volume of 0 mutes the audio).--silenceappends that many milliseconds of silence after each sentence;--ratealso changes how long that silence lasts, because the silence is processed like the rest of the audio. -
--length-scale,--noise-scaleand--noise-woverride inference knobs:--noise-wis Piper’s, while--length-scaleand--noise-scalealso apply to MeloTTS.--param KEY=VALUE(repeatable) sets a named backend parameter to a number, such as MeloTTS’snoise_scale_w(an unrecognized key may be silently ignored); a named flag wins over a conflicting--param.
Managing voices
dengjen voices lists, installs and removes Piper voices from the catalogue. Voices live in
~/.local/share/dengjen/voices (the platform data directory elsewhere).
dengjen voices # same as `dengjen voices list`
dengjen voices list --lang ku --json # JSON array on stdout
dengjen voices list --installed # works offline
dengjen voices install ku_TR-berfin_renas-medium
dengjen speak ku_TR-berfin_renas-medium -f input.txt -o output.wav
dengjen voices remove ku_TR-berfin_renas-medium
dengjen voices refresh # re-download the catalogue, print the voice count
Results go to stdout, with installed voices marked (installed in the table, "installed": true in JSON); progress and errors go to stderr. Exit codes: 0 success, 1 error, 2
another install or removal of the same voice is running. Override the locations with
--voices-dir, --catalogue-url and --files-base-url (accepted before or after the subcommand; speak also takes --voices-dir), or the DENGJEN_VOICES_DIR,
DENGJEN_CATALOGUE_URL and DENGJEN_FILES_BASE_URL environment variables. Ctrl-C stops an
install; running it again resumes the download.