# pnnbao97/vieneu-tts architecture

> Architecture diagram of the GitHub repository pnnbao97/vieneu-tts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pnnbao97/vieneu-tts
- Repository: https://github.com/pnnbao97/vieneu-tts

## Overview

#### 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: [`src/vieneu/factory.py`](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/factory.py) (Engine factory), [`src/vieneu/_v3_turbo_engine/inference_v3_turbo.py`](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/inference_v3_turbo.py) (v3 inference pipeline), [`src/vieneu/__init__.py`](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/__init__.py) (Public SDK), [`src/vieneu/v3turbo.py`](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/v3turbo.py) (v3 Turbo adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User Interfaces"]
  node_gradio["Gradio UI<br/>interface<br/>[gradio_main.py]"]
  node_xpu_ui["XPU Gradio UI<br/>interface<br/>[gradio_xpu.py]"]
  node_web_stream["Streaming web demo<br/>FastAPI app<br/>[web_stream.py]"]
end

subgraph group_sdk["SDK &amp; Engine Selection"]
  node_public_sdk["Public SDK<br/>Python API<br/>[__init__.py]"]
  node_factory{{"Engine factory<br/>engine router<br/>[factory.py]"}}
  node_engine_base["Engine contract<br/>base class<br/>[base.py]"]
  node_legacy_engines["Legacy local engines<br/>v1/v2 engines<br/>[standard.py]"]
  node_remote_client["Remote SDK client<br/>API client<br/>[remote.py]"]
end

subgraph group_v3["v3 Turbo Synthesis"]
  node_v3_adapter["v3 Turbo adapter<br/>SDK engine<br/>[v3turbo.py]"]
  node_text_prep["Text preparation<br/>phonemizer<br/>[phonemize_text.py]"]
  node_v3_inference{{"v3 inference pipeline<br/>synthesis orchestrator"}}
  node_prompting["Speaker/style prompts<br/>conditioning<br/>[prompt_v3_turbo.py]"]
  node_speaker_extract["Reference extractor<br/>ONNX speaker encoder<br/>[onnx_extractor.py]"]
  node_v3_model["PyTorch v3 model<br/>acoustic/codec model"]
  node_onnx_runtime["CPU ONNX runtime<br/>lightweight inference"]
end

subgraph group_serving["Deployment &amp; Serving"]
  node_serve_engine{{"High-throughput v3 server<br/>batched CUDA engine<br/>[engine.py]"}}
  node_server_module["Server module<br/>deployment server<br/>[serve.py]"]
  node_legacy_deployment["Legacy GPU deployment<br/>LMDeploy container<br/>[Dockerfile.serve]"]
end

subgraph group_assets["Models &amp; Voice Assets"]
  node_voice_assets["Voice presets &amp; samples<br/>bundled assets"]
  node_model_hub[("Hugging Face artifacts<br/>model distribution")]
end

node_gradio -->|"synthesis requests"| node_public_sdk
node_xpu_ui -->|"XPU requests"| node_public_sdk
node_web_stream -->|"streaming requests"| node_public_sdk
node_public_sdk -->|"creates engine"| node_factory
node_factory -.->|"shared interface"| node_engine_base
node_factory -->|"v3 Turbo"| node_v3_adapter
node_factory -->|"standard / fast / turbo"| node_legacy_engines
node_factory -->|"remote mode"| node_remote_client
node_v3_adapter -->|"normalize and phonemize"| node_text_prep
node_v3_adapter -->|"synthesize"| node_v3_inference
node_text_prep -->|"phonemes"| node_v3_inference
node_voice_assets -->|"preset voice data"| node_prompting
node_speaker_extract -->|"reference features"| node_prompting
node_prompting -->|"speaker/style conditioning"| node_v3_inference
node_v3_inference -->|"GPU PyTorch path"| node_v3_model
node_v3_inference -->|"CPU/streaming path"| node_onnx_runtime
node_model_hub -->|"loads weights"| node_v3_model
node_model_hub -->|"loads ONNX artifacts"| node_onnx_runtime
node_server_module -->|"GPU serving"| node_serve_engine
node_serve_engine -->|"batched model execution"| node_v3_model
node_remote_client -->|"legacy API"| node_legacy_deployment

click node_gradio "https://github.com/pnnbao97/vieneu-tts/blob/main/apps/gradio_main.py"
click node_xpu_ui "https://github.com/pnnbao97/vieneu-tts/blob/main/apps/gradio_xpu.py"
click node_web_stream "https://github.com/pnnbao97/vieneu-tts/blob/main/apps/web_stream.py"
click node_public_sdk "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/__init__.py"
click node_factory "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/factory.py"
click node_engine_base "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/base.py"
click node_legacy_engines "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/standard.py"
click node_remote_client "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/remote.py"
click node_v3_adapter "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/v3turbo.py"
click node_text_prep "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu_utils/phonemize_text.py"
click node_v3_inference "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/inference_v3_turbo.py"
click node_prompting "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/prompt_v3_turbo.py"
click node_speaker_extract "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/speaker/onnx_extractor.py"
click node_v3_model "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/modeling_v3_turbo.py"
click node_onnx_runtime "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/onnx_runtime_lite.py"
click node_voice_assets "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/assets/voices_v3_turbo.json"
click node_model_hub "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/hub_load_v3_turbo.py"
click node_serve_engine "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/v3_turbo_serve/engine.py"
click node_server_module "https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/serve.py"
click node_legacy_deployment "https://github.com/pnnbao97/vieneu-tts/blob/main/docker/Dockerfile.serve"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gradio,node_xpu_ui,node_web_stream toneBlue
class node_public_sdk,node_factory,node_engine_base,node_legacy_engines,node_remote_client toneAmber
class node_v3_adapter,node_text_prep,node_v3_inference,node_prompting,node_speaker_extract,node_v3_model,node_onnx_runtime toneMint
class node_serve_engine,node_server_module,node_legacy_deployment toneRose
class node_voice_assets,node_model_hub toneIndigo
```

## Components

### User Interfaces

- [Gradio UI](https://github.com/pnnbao97/vieneu-tts/blob/main/apps/gradio_main.py): interface · `apps/gradio_main.py`
- [XPU Gradio UI](https://github.com/pnnbao97/vieneu-tts/blob/main/apps/gradio_xpu.py): interface · `apps/gradio_xpu.py`
- [Streaming web demo](https://github.com/pnnbao97/vieneu-tts/blob/main/apps/web_stream.py): FastAPI app · `apps/web_stream.py`

### SDK & Engine Selection

- [Public SDK](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/__init__.py): Python API · `src/vieneu/__init__.py`
- [Engine factory](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/factory.py): engine router · Selects v3, legacy, XPU, or remote execution. · `src/vieneu/factory.py`
- [Engine contract](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/base.py): base class · `src/vieneu/base.py`
- [Legacy local engines](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/standard.py): v1/v2 engines · `src/vieneu/standard.py`
- [Remote SDK client](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/remote.py): API client · `src/vieneu/remote.py`

### v3 Turbo Synthesis

- [v3 Turbo adapter](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/v3turbo.py): SDK engine · `src/vieneu/v3turbo.py`
- [Text preparation](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu_utils/phonemize_text.py): phonemizer · `src/vieneu_utils/phonemize_text.py`
- [v3 inference pipeline](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/inference_v3_turbo.py): synthesis orchestrator · Builds audio from text and speaker/style prompts. · `src/vieneu/_v3_turbo_engine/inference_v3_turbo.py`
- [Speaker/style prompts](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/prompt_v3_turbo.py): conditioning · `src/vieneu/_v3_turbo_engine/prompt_v3_turbo.py`
- [Reference extractor](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/speaker/onnx_extractor.py): ONNX speaker encoder · `src/vieneu/_v3_turbo_engine/speaker/onnx_extractor.py`
- [PyTorch v3 model](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/modeling_v3_turbo.py): acoustic/codec model · `src/vieneu/_v3_turbo_engine/modeling_v3_turbo.py`
- [CPU ONNX runtime](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/onnx_runtime_lite.py): lightweight inference · Supports int8 and streaming execution. · `src/vieneu/_v3_turbo_engine/onnx_runtime_lite.py`

### Deployment & Serving

- [High-throughput v3 server](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/v3_turbo_serve/engine.py): batched CUDA engine · Batches backbone and acoustic stages for GPU serving. · `src/vieneu/v3_turbo_serve/engine.py`
- [Server module](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/serve.py): deployment server · `src/vieneu/serve.py`
- [Legacy GPU deployment](https://github.com/pnnbao97/vieneu-tts/blob/main/docker/Dockerfile.serve): LMDeploy container · `docker/Dockerfile.serve`

### Models & Voice Assets

- [Voice presets & samples](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/assets/voices_v3_turbo.json): bundled assets · `src/vieneu/assets/voices_v3_turbo.json`
- [Hugging Face artifacts](https://github.com/pnnbao97/vieneu-tts/blob/main/src/vieneu/_v3_turbo_engine/hub_load_v3_turbo.py): model distribution · `src/vieneu/_v3_turbo_engine/hub_load_v3_turbo.py`

## Connections

- 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
