# kittenml/kitten-tts-2-cpp architecture

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

- Interactive diagram: https://gitdiagram.com/kittenml/kitten-tts-2-cpp
- Repository: https://github.com/kittenml/kitten-tts-2-cpp

## Overview

This fork’s README describes KittenTTS2 as a batch CPU speech-synthesis CLI: users provide text and voice/options, the runtime prepares or downloads mode-specific assets, generates tokens, decodes waveforms, and writes WAV output. The tree does not include the documented Kitten-specific runtime files, so those nodes use null paths; llama.cpp and GGML paths are included where the tree supports them. Edges are based on README statements, not an inspection of unsampled runtime code.

Main entry points: [`include/llama.h`](https://github.com/kittenml/kitten-tts-2-cpp/blob/main/include/llama.h) (llama.cpp runtime), [`src/llama-context.cpp`](https://github.com/kittenml/kitten-tts-2-cpp/blob/main/src/llama-context.cpp) (Inference context), [`ggml/include/ggml.h`](https://github.com/kittenml/kitten-tts-2-cpp/blob/main/ggml/include/ggml.h) (GGML compute)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_speech["Speech workflow"]
  node_tts["TTS CLI"]
  node_normalize["Text normalization"]
  node_chunk["Sentence chunking"]
  node_sampling["Sampling controls"]
  node_normalizer_dep["Text-processing submodule"]
end

subgraph group_assets["Model assets"]
  node_asset_repo[("Model repository")]
  node_downloader["Asset downloads"]
  node_cache[("Asset cache")]
  node_gguf["GGUF model"]
  node_voice["Voice conditioning"]
  node_decoder_asset["Decoder exports"]
end

subgraph group_inference["Inference runtime"]
  node_llama["llama.cpp runtime<br/>[llama.h]"]
  node_context["Inference context<br/>[llama-context.cpp]"]
  node_ggml["GGML compute<br/>[ggml.h]"]
end

subgraph group_audio["Audio output"]
  node_decoder["S3 waveform decoder"]
  node_join["Audio joins"]
  node_wav["24 kHz WAV"]
end

node_user(("CLI user"))
node_torch["CPU LibTorch"]

node_user -->|"provides options"| node_tts
node_tts -->|"prepares assets"| node_downloader
node_downloader -->|"fetches assets"| node_asset_repo
node_downloader -->|"caches assets"| node_cache
node_tts -->|"normalizes text"| node_normalize
node_normalize -->|"uses"| node_normalizer_dep
node_tts -->|"chunks sentences"| node_chunk
node_tts -->|"configures sampling"| node_sampling
node_tts -->|"runs inference"| node_llama
node_cache -->|"supplies model"| node_gguf
node_cache -->|"supplies conditioning"| node_voice
node_cache -->|"supplies decoder"| node_decoder_asset
node_llama -.->|"provides context API"| node_context
node_context -->|"computes graphs"| node_ggml
node_tts -->|"decodes waveforms"| node_decoder
node_decoder -->|"uses"| node_torch
node_decoder -->|"produces chunks"| node_join
node_join -->|"writes audio"| node_wav

click node_llama "https://github.com/kittenml/kitten-tts-2-cpp/blob/main/include/llama.h"
click node_context "https://github.com/kittenml/kitten-tts-2-cpp/blob/main/src/llama-context.cpp"
click node_ggml "https://github.com/kittenml/kitten-tts-2-cpp/blob/main/ggml/include/ggml.h"

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_tts,node_normalize,node_chunk,node_sampling,node_normalizer_dep,node_user toneBlue
class node_asset_repo,node_downloader,node_cache,node_gguf,node_voice,node_decoder_asset toneAmber
class node_llama,node_context,node_ggml toneMint
class node_decoder,node_join,node_wav toneRose
class node_torch toneIndigo
```

## Components

### Speech workflow

- **TTS CLI**
- **Text normalization**
- **Sentence chunking**
- **Sampling controls**
- **Text-processing submodule**

### Model assets

- **Model repository**
- **Asset downloads**
- **Asset cache**
- **GGUF model**
- **Voice conditioning**
- **Decoder exports**

### Inference runtime

- [llama.cpp runtime](https://github.com/kittenml/kitten-tts-2-cpp/blob/main/include/llama.h): `include/llama.h`
- [Inference context](https://github.com/kittenml/kitten-tts-2-cpp/blob/main/src/llama-context.cpp): `src/llama-context.cpp`
- [GGML compute](https://github.com/kittenml/kitten-tts-2-cpp/blob/main/ggml/include/ggml.h): `ggml/include/ggml.h`

### Audio output

- **S3 waveform decoder**
- **Audio joins**
- **24 kHz WAV**

### Other components

- **CLI user**
- **CPU LibTorch**

## Connections

- CLI user → TTS CLI: provides options (evidence: `README.md`)
- TTS CLI → Asset downloads: prepares assets (evidence: `README.md`)
- Asset downloads → Model repository: fetches assets (evidence: `README.md`)
- Asset downloads → Asset cache: caches assets (evidence: `README.md`)
- TTS CLI → Text normalization: normalizes text (evidence: `README.md`)
- Text normalization → Text-processing submodule: uses (evidence: `README.md`)
- TTS CLI → Sentence chunking: chunks sentences (evidence: `README.md`)
- TTS CLI → Sampling controls: configures sampling (evidence: `README.md`)
- TTS CLI → llama.cpp runtime: runs inference (evidence: `README.md`)
- Asset cache → GGUF model: supplies model (evidence: `README.md`)
- Asset cache → Voice conditioning: supplies conditioning (evidence: `README.md`)
- Asset cache → Decoder exports: supplies decoder (evidence: `README.md`)
- llama.cpp runtime → Inference context: provides context API (evidence: `src/llama-context.cpp`)
- Inference context → GGML compute: computes graphs (evidence: `src/llama-context.cpp`)
- TTS CLI → S3 waveform decoder: decodes waveforms (evidence: `README.md`)
- S3 waveform decoder → CPU LibTorch: uses (evidence: `README.md`)
- S3 waveform decoder → Audio joins: produces chunks (evidence: `README.md`)
- Audio joins → 24 kHz WAV: writes audio (evidence: `README.md`)
