How kyutai-labs/pocket-tts works
1. Pocket TTS is a single Python package centered on on-device text-to-speech generation. The architecture is built around a small CPU-friendly model, with a clean split between model logic, audio handling, voice conditioning, CLI/server entrypoints, and supporting utilities.
2. The main public entrypoints are:
- pocket_tts/__init__.py and pocket_tts/main.py for the Python API
- pocket_tts/__main__.py plus pocket_tts/main.py for the CLI
- pocket_tts/static/index.html for the local web UI used by the server mode
The same underlying model pipeline is reused by CLI generation, the HTTP server, and library calls.
3. The core orchestration lives in pocket_tts/models/tts_model.py. This is the high-level façade that loads weights, builds the model, prepares voice state from audio or cached state, and exposes audio generation. It is the main boundary between user-facing inputs and the neural inference stack.
4. The model itself is split into two major learned subsystems:
- pocket_tts/models/flow_lm.py: the text-to-audio latent generation / language-model-like component
- pocket_tts/models/mimi.py: the audio codec / representation side used to turn latent predictions into waveform output
The naming and structure suggest a staged pipeline: text conditioning first, then latent/audio generation, then PCM output.
5. Voice cloning is a first-class path. The conditioners/ and data/ layers handle prompt audio and text conditioning:
- conditioners/text.py and conditioners/base.py define conditioning interfaces
- data/audio.py and data/audio_utils.py handle waveform loading, preprocessing, and sample-rate/audio-format concerns
A voice state can come from a raw audio file or from a pre-exported serialized state, which is what enables fast reuse.
6. The repository explicitly supports exporting and reloading voice state for speed. The README’s export_model_state flow maps to the codebase’s stateful inference design and the presence of modules/stateful_module.py. This is important architecturally because long-form or repeated generation avoids recomputing prompt-derived caches.
7. pocket_tts/config/*.yaml holds model variants and language-specific settings. These configs are part of the loading boundary: pretrained language/model variants are selected by config, while custom weights are supported via local YAML paths. The included English, French, German, Italian, Portuguese, and Spanish configs reflect the multi-language deployment surface.
8. pocket_tts/modules/ contains the reusable neural building blocks that make the model portable and CPU-efficient: transformer components, convolution/resampling layers, RoPE, MLPs, layer scaling, SEANet-style audio blocks, and a dummy quantizer. This layer is the implementation substrate for both the flow model and the audio codec.
9. pocket_tts/quantization.py and scripts/evaluate_quantization.py show that quantization is a distinct concern, not an afterthought. The repo treats quantized execution as a performance/size optimization path, which matters for the CPU-first runtime and for maintaining real-time or better-than-real-time generation.
10. pocket_tts/utils/ handles cross-cutting concerns: config parsing, logging, debugging, weight loading, and general helpers. utils/weights_loading.py is especially important because the model is designed to load from packaged weights, local custom configs, and Hugging Face-style voice assets.
11. The project is packaged and deployable in multiple ways:
- Dockerfile, docker-compose.yaml, docker-bake.hcl, and deploy.sh support containerized use
- GitHub Actions workflows automate tests, package publishing, and documentation deployment
- mkdocs.yml and the docs/ tree define the generated documentation site
This makes the repo both a library and an operational application.
12. The test suite covers the main architectural boundaries rather than only unit internals:
- CLI generation behavior
- Python API behavior
- sentence splitting
- quantization
- documentation examples
That tells you the stable contract is the end-to-end TTS pipeline, not just isolated model modules.
13. For an architecture diagram, the most important flow is:
user text + voice prompt → conditioning/audio preprocessing → TTSModel orchestration → stateful latent generation model → audio codec / waveform reconstruction → PCM audio output or WAV file.
The server and CLI are thin wrappers around this same pipeline.
14. The main external dependency boundary is Hugging Face-hosted model/voice assets, plus PyTorch as the runtime. Those assets are not just data files; they are part of the model-loading and voice-cloning workflow, so they should appear as an external model/asset source in any diagram.
Main entry points: tts_model.py TTS Model · main.py Main API · modules Modules · __main__.py CLI entrypoint
Components 19
Entrypoints
Public API, CLI, and local server UI
- Package API · Public library entrypoint for importing Pocket TTS
pocket_tts/__init__.py - Main API · Shared runtime surface for library calls and generation
pocket_tts/main.py - CLI entrypoint · Module entrypoint for command-line generation and serving
pocket_tts/__main__.py - Web UI · Local browser interface used by server mode
pocket_tts/static/index.html
Core model
High-level orchestration and learned inference stack
- TTS Model · Loads weights, builds the model, prepares voice state, and runs generation
pocket_tts/models/tts_model.py - Flow LM · Text-conditioned latent prediction stack
pocket_tts/models/flow_lm.py - Mimi Codec · Audio representation and waveform reconstruction path
pocket_tts/models/mimi.py - Stateful Module · Reusable state and prompt-derived cache handling
pocket_tts/modules/stateful_module.py
Conditioning
Prompt text and audio preparation for voice cloning
- Text Conditioner · Text conditioning interfaces and implementations
pocket_tts/conditioners/text.py - Conditioning Base · Shared conditioning abstractions
pocket_tts/conditioners/base.py - Audio I/O · Waveform loading, preprocessing, and sample-rate handling
pocket_tts/data/audio.py - Audio Utils · Low-level audio helper routines
pocket_tts/data/audio_utils.py
Infrastructure
Reusable building blocks, config, utils, and quantization
- Modules · Shared transformer, convolution, resampling, RoPE, MLP, and SEANet-style blocks
pocket_tts/modules - Config YAMLs · Language and model variant selection files
pocket_tts/config - Weights Loader · Loading packaged weights, custom configs, and voice assets
pocket_tts/utils/weights_loading.py - Core Utils · Config parsing, logging, debugging, and helper functions
pocket_tts/utils - Quantization · Quantized execution path for CPU-friendly deployment
pocket_tts/quantization.py
External runtime
Model assets and compute backend outside the repository
- Model Assets · Hugging Face-hosted pretrained models and voice files
- PyTorch · Neural network execution backend
Connections 21
- Package API → Main API: exports · Package import surface forwards to shared API
- CLI entrypoint → Main API: invokes · CLI uses the same generation API
- Main API → TTS Model: drives · Shared API delegates synthesis to the orchestrator
- TTS Model → Flow LM: runs · High-level model calls the latent generation stack
- TTS Model → Mimi Codec: decodes · Waveform reconstruction goes through the audio codec
- TTS Model → Stateful Module: caches · Prompt-derived voice state is managed as reusable state
- TTS Model → Text Conditioner: conditions · Text and prompt conditioning are prepared before inference
- TTS Model → Audio I/O: loads audio · Voice prompts and input audio are preprocessed from files
- Audio I/O → Audio Utils: uses · Audio preprocessing relies on helper routines
- Text Conditioner → Conditioning Base: implements · Text conditioning follows shared interfaces
- Flow LM → Modules: built from · Flow model is assembled from reusable neural blocks
- Mimi Codec → Modules: built from · Codec uses the same portable building blocks
- Stateful Module → Weights Loader: restores · State and weights are loaded through dedicated loaders
- TTS Model → Config YAMLs: configured by · Model variants and language settings come from YAML configs
- Weights Loader → Model Assets: fetches · Loader can resolve pretrained and voice assets from external storage
- TTS Model → PyTorch: executes on · Inference runs on the PyTorch backend
- Modules → PyTorch: depends on · Neural building blocks are implemented for the runtime backend
- Quantization → PyTorch: optimizes · Quantization shapes the deployment runtime
- Main API → Quantization: exposes · API surface includes quantized execution support
- CLI entrypoint → Web UI: serves · Server mode presents the local web UI
- Web UI → Main API: calls · Web UI talks to the shared generation API