How jianchang512/chattts-ui works
Project Type & Purpose
• This is a full‑stack Python web application (“ChatTTS webUI & API”) that provides a browser‑based UI and a RESTful API for on‑premise text‑to‑speech synthesis.
• The backend is a Flask/FastAPI‑style server (app.py/run.py) embedding the ChatTTS engine (in the ChatTTS/ package), and the frontend is a simple HTML/JS interface (templates/ + static/).
High‑Level Components
a. Frontend
• templates/index.html, indexen.html
• static/js/layer (layer.js, CSS themes)
b. API/Web Server
• app.py, run.py (entrypoints)
• ChatTTS/infer/api.py (HTTP endpoint logic)
• Dockerfiles & docker‑compose for CPU/GPU deployment
c. ChatTTS Core Engine
• ChatTTS/core.py (orchestrator)
• ChatTTS/config/config.py (singleton config loader)
• ChatTTS/norm.py + uilib/zh_normalization (text normalization)
• ChatTTS/model/ (model definitions & CUDA patches)
• ChatTTS/model/tokenizer.py, processors.py (pre/post‑processing)
d. Inference Compute
• CPU path: torch, torchaudio, pure‑Python inference
• GPU path: ChatTTS/model/cuda/*, PyTorch‑CUDA kernels
• FFmpeg (external binary) for audio merging/post‑processing
e. Assets & Storage
• asset/ (download scripts, pt files)
• speaker/ (converted speaker embeddings)
• static/wavs/ (generated audio files)
f. Utilities & Tools
• ChatTTS/utils/* (download, I/O, logging, GPU detection)
• tools/ (CLI helpers in Go/Python, not part of runtime)
Component Interactions & Data Flow
1. User (Browser) → HTTP Request (GET /) → Web Server serves HTML/JS.
2. User triggers TTS → HTTP POST /tts → infer/api.py
3. API layer pulls parameters → calls ChatTTS/core.py
4. core.py invokes:
a. Text normalization (norm.py + uilib)
b. Tokenization & prompt processing (model/tokenizer.py)
c. Model inference via CPU or GPU modules (model/dvae.py, model/gpt.py, model/cuda/…)
5. Generated raw audio segments → post‑process via FFmpeg
6. Write .wav to static/wavs/ → return JSON {code, msg, audio_files:[…URL…]}
7. Browser/Client downloads and plays back audio
Architectural Patterns & Principles
• MVC‑style separation:
• View = templates/ + static/
• Controller = app.py + infer/api.py
• Model = ChatTTS package & PyTorch models
• Singleton configuration (config/config.py)
• Pluggable compute backends (CPU vs CUDA vs ROCm)
• Lazy download & caching of model files (utils/download.py)
• Modular normalization pipeline (uilib + ChatTTS/norm.py)