# 2noise/chattts architecture

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

- Interactive diagram: https://gitdiagram.com/2noise/chattts
- Repository: https://github.com/2noise/chattts

## Overview

ChatTTS is a dialogue-oriented text-to-speech model. The principal workflow is a user submitting text to `Chat`, which can normalize and refine it, generate speech codes, and decode those codes into audio; documented controls include speaker selection, prosody tokens, and streaming. Model inference uses a GPU-oriented generation engine with scheduling and token-block management. The graph reflects README capabilities and the supplied source index/excerpts; several model details are indexed but not excerpted, so their runtime connections are shown only where the evidence supports them.

Main entry points: [`ChatTTS/model/velocity/llm_engine.py`](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/llm_engine.py) (LLM engine), [`ChatTTS/core.py`](https://github.com/2noise/chattts/blob/main/ChatTTS/core.py) (Chat API), [`ChatTTS/model/velocity/llm.py`](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/llm.py) (Generation interface), [`ChatTTS/model/velocity/sequence.py`](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/sequence.py) (Sequence state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Speech workflow"]
  node_chat["Chat API<br/>[core.py]"]
  node_normalizer["Text normalization<br/>[norm.py]"]
  node_vocoder["Audio decoding<br/>[core.py]"]
end

subgraph group_model["Speech models"]
  node_tokenizer["Tokenization<br/>[tokenizer.py]"]
  node_processors["Text processors<br/>[processors.py]"]
  node_gpt["Speech-code GPT<br/>[gpt.py]"]
  node_speaker["Speaker encoding<br/>[speaker.py]"]
  node_embed["Model embeddings<br/>[embed.py]"]
  node_dvae["DVAE encoder<br/>[dvae.py]"]
end

subgraph group_engine["Inference engine"]
  node_velocity_llm["Generation interface<br/>[llm.py]"]
  node_engine_args["Engine configuration<br/>[configs.py]"]
  node_llm_engine["LLM engine<br/>[llm_engine.py]"]
  node_sampling["Sampling controls<br/>[sampling_params.py]"]
  node_scheduler["Request scheduler<br/>[scheduler.py]"]
  node_sequence["Sequence state<br/>[sequence.py]"]
  node_blocks["Token block manager<br/>[block_manager.py]"]
  node_worker["GPU worker<br/>[worker.py]"]
  node_runner["Model runner<br/>[model_runner.py]"]
  node_outputs["Generation outputs<br/>[output.py]"]
end

subgraph group_support["Runtime support"]
  node_asset_support["Model asset checks<br/>[dl.py]"]
  node_file_io["Tensor file loading<br/>[io.py]"]
end

node_user(("Text caller"))

node_user -->|"submits text"| node_chat
node_chat -->|"normalizes text"| node_normalizer
node_chat -->|"generates codes"| node_gpt
node_chat -->|"decodes codes"| node_vocoder
node_chat -->|"checks assets"| node_asset_support
node_gpt -->|"uses embeddings"| node_embed
node_gpt -->|"uses generation"| node_velocity_llm
node_velocity_llm -->|"builds arguments"| node_engine_args
node_velocity_llm -->|"creates engine"| node_llm_engine
node_velocity_llm -->|"accepts sampling"| node_sampling
node_llm_engine -->|"dispatches requests"| node_scheduler
node_llm_engine -->|"dispatches work"| node_worker
node_llm_engine -->|"creates sequences"| node_sequence
node_llm_engine -->|"uses parameters"| node_sampling
node_llm_engine -->|"returns results"| node_outputs
node_scheduler -->|"allocates token blocks"| node_blocks
node_scheduler -->|"schedules sequences"| node_sequence
node_worker -->|"executes model"| node_runner
node_blocks -->|"manages sequence blocks"| node_sequence
node_sequence -->|"stores sampling settings"| node_sampling
node_dvae -->|"loads model tensors"| node_file_io
node_embed -->|"loads model tensors"| node_file_io
node_tokenizer -->|"uses shared utilities"| node_file_io

click node_chat "https://github.com/2noise/chattts/blob/main/ChatTTS/core.py"
click node_normalizer "https://github.com/2noise/chattts/blob/main/ChatTTS/norm.py"
click node_tokenizer "https://github.com/2noise/chattts/blob/main/ChatTTS/model/tokenizer.py"
click node_processors "https://github.com/2noise/chattts/blob/main/ChatTTS/model/processors.py"
click node_gpt "https://github.com/2noise/chattts/blob/main/ChatTTS/model/gpt.py"
click node_speaker "https://github.com/2noise/chattts/blob/main/ChatTTS/model/speaker.py"
click node_embed "https://github.com/2noise/chattts/blob/main/ChatTTS/model/embed.py"
click node_dvae "https://github.com/2noise/chattts/blob/main/ChatTTS/model/dvae.py"
click node_velocity_llm "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/llm.py"
click node_engine_args "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/configs.py"
click node_llm_engine "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/llm_engine.py"
click node_sampling "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/sampling_params.py"
click node_scheduler "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/scheduler.py"
click node_sequence "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/sequence.py"
click node_blocks "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/block_manager.py"
click node_worker "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/worker.py"
click node_runner "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/model_runner.py"
click node_outputs "https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/output.py"
click node_asset_support "https://github.com/2noise/chattts/blob/main/ChatTTS/utils/dl.py"
click node_file_io "https://github.com/2noise/chattts/blob/main/ChatTTS/utils/io.py"
click node_vocoder "https://github.com/2noise/chattts/blob/main/ChatTTS/core.py"

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_chat,node_normalizer,node_vocoder toneBlue
class node_tokenizer,node_processors,node_gpt,node_speaker,node_embed,node_dvae toneAmber
class node_velocity_llm,node_engine_args,node_llm_engine,node_sampling,node_scheduler,node_sequence,node_blocks,node_worker,node_runner,node_outputs toneMint
class node_asset_support,node_file_io toneRose
class node_user toneIndigo
```

## Components

### Speech workflow

- [Chat API](https://github.com/2noise/chattts/blob/main/ChatTTS/core.py): `ChatTTS/core.py`
- [Text normalization](https://github.com/2noise/chattts/blob/main/ChatTTS/norm.py): `ChatTTS/norm.py`
- [Audio decoding](https://github.com/2noise/chattts/blob/main/ChatTTS/core.py): `ChatTTS/core.py`

### Speech models

- [Tokenization](https://github.com/2noise/chattts/blob/main/ChatTTS/model/tokenizer.py): `ChatTTS/model/tokenizer.py`
- [Text processors](https://github.com/2noise/chattts/blob/main/ChatTTS/model/processors.py): `ChatTTS/model/processors.py`
- [Speech-code GPT](https://github.com/2noise/chattts/blob/main/ChatTTS/model/gpt.py): `ChatTTS/model/gpt.py`
- [Speaker encoding](https://github.com/2noise/chattts/blob/main/ChatTTS/model/speaker.py): `ChatTTS/model/speaker.py`
- [Model embeddings](https://github.com/2noise/chattts/blob/main/ChatTTS/model/embed.py): `ChatTTS/model/embed.py`
- [DVAE encoder](https://github.com/2noise/chattts/blob/main/ChatTTS/model/dvae.py): `ChatTTS/model/dvae.py`

### Inference engine

- [Generation interface](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/llm.py): `ChatTTS/model/velocity/llm.py`
- [Engine configuration](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/configs.py): `ChatTTS/model/velocity/configs.py`
- [LLM engine](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/llm_engine.py): `ChatTTS/model/velocity/llm_engine.py`
- [Sampling controls](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/sampling_params.py): `ChatTTS/model/velocity/sampling_params.py`
- [Request scheduler](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/scheduler.py): `ChatTTS/model/velocity/scheduler.py`
- [Sequence state](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/sequence.py): `ChatTTS/model/velocity/sequence.py`
- [Token block manager](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/block_manager.py): `ChatTTS/model/velocity/block_manager.py`
- [GPU worker](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/worker.py): `ChatTTS/model/velocity/worker.py`
- [Model runner](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/model_runner.py): `ChatTTS/model/velocity/model_runner.py`
- [Generation outputs](https://github.com/2noise/chattts/blob/main/ChatTTS/model/velocity/output.py): `ChatTTS/model/velocity/output.py`

### Runtime support

- [Model asset checks](https://github.com/2noise/chattts/blob/main/ChatTTS/utils/dl.py): `ChatTTS/utils/dl.py`
- [Tensor file loading](https://github.com/2noise/chattts/blob/main/ChatTTS/utils/io.py): `ChatTTS/utils/io.py`

### Other components

- **Text caller**

## Connections

- Text caller → Chat API: submits text (evidence: `README.md`)
- Chat API → Text normalization: normalizes text (evidence: `ChatTTS/core.py`)
- Chat API → Speech-code GPT: generates codes (evidence: `ChatTTS/core.py`)
- Chat API → Audio decoding: decodes codes (evidence: `ChatTTS/core.py`)
- Chat API → Model asset checks: checks assets (evidence: `ChatTTS/core.py`)
- Speech-code GPT → Model embeddings: uses embeddings (evidence: `ChatTTS/model/gpt.py`)
- Speech-code GPT → Generation interface: uses generation (evidence: `ChatTTS/model/gpt.py`)
- Generation interface → Engine configuration: builds arguments (evidence: `ChatTTS/model/velocity/llm.py`)
- Generation interface → LLM engine: creates engine (evidence: `ChatTTS/model/velocity/llm.py`)
- Generation interface → Sampling controls: accepts sampling (evidence: `ChatTTS/model/velocity/llm.py`)
- LLM engine → Request scheduler: dispatches requests (evidence: `ChatTTS/model/velocity/llm_engine.py`)
- LLM engine → GPU worker: dispatches work (evidence: `ChatTTS/model/velocity/llm_engine.py`)
- LLM engine → Sequence state: creates sequences (evidence: `ChatTTS/model/velocity/llm_engine.py`)
- LLM engine → Sampling controls: uses parameters (evidence: `ChatTTS/model/velocity/llm_engine.py`)
- LLM engine → Generation outputs: returns results (evidence: `ChatTTS/model/velocity/llm_engine.py`)
- Request scheduler → Token block manager: allocates token blocks (evidence: `ChatTTS/model/velocity/scheduler.py`)
- Request scheduler → Sequence state: schedules sequences (evidence: `ChatTTS/model/velocity/scheduler.py`)
- GPU worker → Model runner: executes model (evidence: `ChatTTS/model/velocity/worker.py`)
- Token block manager → Sequence state: manages sequence blocks (evidence: `ChatTTS/model/velocity/block_manager.py`)
- Sequence state → Sampling controls: stores sampling settings (evidence: `ChatTTS/model/velocity/sequence.py`)
- DVAE encoder → Tensor file loading: loads model tensors (evidence: `ChatTTS/model/dvae.py`)
- Model embeddings → Tensor file loading: loads model tensors (evidence: `ChatTTS/model/embed.py`)
- Tokenization → Tensor file loading: uses shared utilities (evidence: `ChatTTS/model/tokenizer.py`)
