This guide provides examples for running TTS inference using example_onnx.py.
2025.11.23 - Enhanced text preprocessing with comprehensive normalization, emoji removal, symbol replacement, and punctuation handling for improved synthesis quality.
2025.11.19 - Added --speed parameter to control speech synthesis speed. Adjust the speed factor to make speech faster or slower while maintaining natural quality.
2025.11.19 - Added automatic text chunking for long-form inference. Long texts are split into chunks and synthesized with natural pauses.
This project uses uv for fast package management.
curl -LsSf https://astral.sh/uv/install.sh | shuv syncOr if you prefer using traditional pip with requirements.txt:
pip install -r requirements.txtRun inference with default settings:
uv run example_onnx.pyThis will use:
- Voice style:
assets/voice_styles/M1.json - Text: "This morning, I took a walk in the park, and the sound of the birds and the breeze was so pleasant that I stopped for a long time just to listen."
- Output directory:
results/ - Total steps: 5
- Number of generations: 4
Process multiple voice styles and texts at once:
uv run example_onnx.py \
--voice-style assets/voice_styles/M1.json assets/voice_styles/F1.json \
--text "The sun sets behind the mountains, painting the sky in shades of pink and orange." "The weather is beautiful and sunny outside. A gentle breeze makes the air feel fresh and pleasant." \
--batchThis will:
- Use
--batchflag to enable batch processing mode - Generate speech for 2 different voice-text pairs
- Use male voice style (M1.json) for the first text
- Use female voice style (F1.json) for the second text
- Process both samples in a single batch (automatic text chunking disabled)
Increase denoising steps for better quality:
uv run example_onnx.py \
--total-step 10 \
--voice-style assets/voice_styles/M1.json \
--text "Increasing the number of denoising steps improves the output's fidelity and overall quality."This will:
- Use 10 denoising steps instead of the default 5
- Produce higher quality output at the cost of slower inference
For long texts, the system automatically chunks the text into manageable segments and generates a single audio file:
uv run example_onnx.py \
--voice-style assets/voice_styles/M1.json \
--text "Once upon a time, in a small village nestled between rolling hills, there lived a young artist named Clara. Every morning, she would wake up before dawn to capture the first light of day. The golden rays streaming through her window inspired countless paintings. Her work was known throughout the region for its vibrant colors and emotional depth. People from far and wide came to see her gallery, and many said her paintings could tell stories that words never could."This will:
- Automatically split the long text into smaller chunks (max 300 characters by default)
- Process each chunk separately while maintaining natural speech flow
- Insert brief silences (0.3 seconds) between chunks for natural pacing
- Combine all chunks into a single output audio file
Note: When using batch mode (--batch), automatic text chunking is disabled. Use non-batch mode for long-form text synthesis.
Control the speed of speech synthesis:
# Faster speech (speed > 1.0)
uv run example_onnx.py \
--voice-style assets/voice_styles/F2.json \
--text "This text will be synthesized at a faster pace." \
--speed 1.2
# Slower speech (speed < 1.0)
uv run example_onnx.py \
--voice-style assets/voice_styles/M2.json \
--text "This text will be synthesized at a slower, more deliberate pace." \
--speed 0.9This will:
- Use
--speed 1.2to generate faster speech - Use
--speed 0.9to generate slower speech - Default speed is 1.05 if not specified
- Recommended speed range is between 0.9 and 1.5 for natural-sounding results
| Argument | Type | Default | Description |
|---|---|---|---|
--use-gpu |
flag | False | Use GPU for inference (with CPU fallback) |
--onnx-dir |
str | assets/onnx |
Path to ONNX model directory |
--total-step |
int | 5 | Number of denoising steps (higher = better quality, slower) |
--speed |
float | 1.05 | Speech speed factor (higher = faster, lower = slower) |
--n-test |
int | 4 | Number of times to generate each sample |
--voice-style |
str+ | assets/voice_styles/M1.json |
Voice style file path(s) |
--text |
str+ | (long default text) | Text(s) to synthesize |
--save-dir |
str | results |
Output directory |
--batch |
flag | False | Enable batch mode (disables automatic text chunking) |
- Batch Processing: The number of
--voice-stylefiles must match the number of--textentries - Long-Form Inference: Without
--batchflag, long texts are automatically chunked and combined into a single audio file with natural pauses - Quality vs Speed: Higher
--total-stepvalues produce better quality but take longer - GPU Support: GPU mode is not supported yet