How pnnbao97/vieneu-tts works
Purpose and entry points
VieNeu-TTS is a Python SDK and deployment stack for Vietnamese/English neural text-to-speech, centered on 48 kHz v3 Turbo while retaining v1/v2, CPU, GPU, and remote-server paths. The public SDK surface is src/vieneu/__init__.py; src/vieneu/factory.py selects an engine behind Vieneu. User-facing entry points include the Gradio UI in apps/gradio_main.py, streaming FastAPI demo in apps/web_stream.py, and server module src/vieneu/serve.py.
Engine selection and compatibility boundary
src/vieneu/factory.py routes modes/backends to distinct implementations: v3 Turbo, legacy standard/fast/turbo, XPU, or a remote client. src/vieneu/base.py establishes shared engine-facing behavior, while src/vieneu/v3turbo.py is the primary modern SDK adapter. This isolates callers from model/runtime differences: callers provide text, voice/reference audio, style, and batching options; selected engines return waveform data.
v3 Turbo synthesis pipeline
The v3 stack lives in src/vieneu/_v3_turbo_engine/inference_v3_turbo.py, src/vieneu/_v3_turbo_engine/modeling_v3_turbo.py, and src/vieneu/_v3_turbo_engine/prompt_v3_turbo.py. It transforms normalized/phonemized text plus speaker/style/emotion prompt data into codec/audio output. Model configuration and Hugging Face artifact loading are separated in src/vieneu/_v3_turbo_engine/configuration_v3_turbo.py and src/vieneu/_v3_turbo_engine/hub_load_v3_turbo.py, defining the boundary between local inference and externally hosted model weights.
CPU/ONNX versus GPU/PyTorch execution
CPU-oriented v3 inference uses ONNX components in src/vieneu/_v3_turbo_engine/onnx_runtime_lite.py and src/vieneu/_v3_turbo_engine/onnx_denoiser.py; it supports lightweight/int8 operation and streaming. GPU execution uses the PyTorch model path and batches work for throughput. Dedicated high-throughput serving components—batched backbone/acoustic stages and CUDA graph support—are under src/vieneu/v3_turbo_serve/engine.py, src/vieneu/v3_turbo_serve/batched_backbone.py, and src/vieneu/v3_turbo_serve/batched_acoustic.py.
Voice assets and cloning
Preset voice metadata and bundled reference assets are stored in src/vieneu/assets/voices_v3_turbo.json, src/vieneu/assets/voices.json, and src/vieneu/assets/samples/. Speaker-reference feature extraction is encapsulated by src/vieneu/_v3_turbo_engine/speaker/onnx_extractor.py and its audio preprocessing modules. This forms a distinct input boundary: named preset voices resolve from assets, while reference clips are denoised/encoded into speaker conditioning.
Legacy and remote deployment paths
Older/local engine variants remain separately implemented in src/vieneu/standard.py, src/vieneu/fast.py, and src/vieneu/turbo.py. src/vieneu/remote.py is a lightweight SDK client for a GPU-hosted standard-mode API; the deployed server uses LMDeploy according to the repository documentation. Docker deployment is defined by docker/Dockerfile.serve and docker/docker-compose.prod.yml, with NVIDIA GPU/container-toolkit expected for high-quality server execution and optional Bore tunneling.
Interfaces, dependencies, and operations
Gradio UI variants are apps/gradio_main.py and apps/gradio_xpu.py; browser streaming is separately exposed through apps/web_stream.py, avoiding coupling the SDK to a single UI/server transport. Core text preparation utilities—including phonemization—are in src/vieneu_utils/phonemize_text.py. Material external dependencies are Hugging Face model distribution, ONNX Runtime for CPU inference, PyTorch/CUDA or Apple MPS for accelerated inference, sea-g2p for phonemization, MOSS-Audio-Tokenizer-Nano for v3 codec processing, and LMDeploy for the legacy remote serving path.
Main entry points: factory.py Engine factory · inference_v3_turbo.py v3 inference pipeline · __init__.py Public SDK · v3turbo.py v3 Turbo adapter
Components 20
User Interfaces
- Gradio UI
apps/gradio_main.py - XPU Gradio UI
apps/gradio_xpu.py - Streaming web demo
apps/web_stream.py
SDK & Engine Selection
- Public SDK
src/vieneu/__init__.py - Engine factory · Selects v3, legacy, XPU, or remote execution.
src/vieneu/factory.py - Engine contract
src/vieneu/base.py - Legacy local engines
src/vieneu/standard.py - Remote SDK client
src/vieneu/remote.py
v3 Turbo Synthesis
- v3 Turbo adapter
src/vieneu/v3turbo.py - Text preparation
src/vieneu_utils/phonemize_text.py - v3 inference pipeline · Builds audio from text and speaker/style prompts.
src/vieneu/_v3_turbo_engine/inference_v3_turbo.py - Speaker/style prompts
src/vieneu/_v3_turbo_engine/prompt_v3_turbo.py - Reference extractor
src/vieneu/_v3_turbo_engine/speaker/onnx_extractor.py - PyTorch v3 model
src/vieneu/_v3_turbo_engine/modeling_v3_turbo.py - CPU ONNX runtime · Supports int8 and streaming execution.
src/vieneu/_v3_turbo_engine/onnx_runtime_lite.py
Deployment & Serving
- High-throughput v3 server · Batches backbone and acoustic stages for GPU serving.
src/vieneu/v3_turbo_serve/engine.py - Server module
src/vieneu/serve.py - Legacy GPU deployment
docker/Dockerfile.serve
Models & Voice Assets
- Voice presets & samples
src/vieneu/assets/voices_v3_turbo.json - Hugging Face artifacts
src/vieneu/_v3_turbo_engine/hub_load_v3_turbo.py
Connections 21
- Gradio UI → Public SDK: synthesis requests
- XPU Gradio UI → Public SDK: XPU requests
- Streaming web demo → Public SDK: streaming requests
- Public SDK → Engine factory: creates engine
- Engine factory → Engine contract: shared interface
- Engine factory → v3 Turbo adapter: v3 Turbo
- Engine factory → Legacy local engines: standard / fast / turbo
- Engine factory → Remote SDK client: remote mode
- v3 Turbo adapter → Text preparation: normalize and phonemize
- v3 Turbo adapter → v3 inference pipeline: synthesize
- Text preparation → v3 inference pipeline: phonemes
- Voice presets & samples → Speaker/style prompts: preset voice data
- Reference extractor → Speaker/style prompts: reference features
- Speaker/style prompts → v3 inference pipeline: speaker/style conditioning
- v3 inference pipeline → PyTorch v3 model: GPU PyTorch path
- v3 inference pipeline → CPU ONNX runtime: CPU/streaming path
- Hugging Face artifacts → PyTorch v3 model: loads weights
- Hugging Face artifacts → CPU ONNX runtime: loads ONNX artifacts
- Server module → High-throughput v3 server: GPU serving
- High-throughput v3 server → PyTorch v3 model: batched model execution
- Remote SDK client → Legacy GPU deployment: legacy API