How openbmb/voxcpm works
1. What this repo is
- This is a Python package for VoxCPM TTS, centered on inference, fine-tuning, and demos for multiple model generations: VoxCPM, VoxCPM1.5, and VoxCPM2.
- The repository is organized as an installable library under src/voxcpm, plus runnable entry points for CLI, training, and web demos.
2. Top-level entry points
- src/voxcpm/cli.py exposes the command-line interface used by the README flows such as design, clone, and batch generation.
- app.py is the main browser-based demo server.
- lora_ft_webui.py is a separate web UI focused on LoRA fine-tuning and inference.
- scripts/*.py contains standalone utilities for training, inference checks, and runtime tests.
3. Core inference boundary
- src/voxcpm/core.py is the main orchestration layer that ties together model loading, generation APIs, streaming, and the different voice modes.
- The public package surface in src/voxcpm/__init__.py likely re-exports the main user-facing model wrapper so applications can call VoxCPM.from_pretrained(...) and generate audio without touching internals.
4. Model versioning
- Version-specific logic lives in src/voxcpm/model/voxcpm.py and src/voxcpm/model/voxcpm2.py.
- src/voxcpm/model/utils.py contains shared model helpers.
- The conf/voxcpm_v1, conf/voxcpm_v1.5, and conf/voxcpm_v2 folders hold versioned YAML configs for full finetuning and LoRA finetuning, which is a strong sign the repo keeps architecture-compatible model variants side by side.
5. Main model pipeline
- The README describes the VoxCPM2 architecture as a four-stage latent-speech pipeline: LocEnc → TSLM → RALM → LocDiT.
- Those stages are reflected in the code layout:
- modules/locenc/ for the local encoder,
- modules/minicpm4/ for the language-model backbone,
- modules/locdit/ for the diffusion/flow-matching speech generator,
- modules/audiovae/ for audio latent encoding/decoding.
- This is the central architectural boundary: the system does not generate waveform samples directly from text; it generates speech latents and then decodes them.
6. Audio subsystem
- src/voxcpm/modules/audiovae/audio_vae.py and audio_vae_v2.py implement the audio representation layer.
- VoxCPM2’s README emphasizes 48 kHz output from 16 kHz reference input, so the AudioVAE layer is not just a compressor; it also serves as the model’s speech-domain interface and reconstruction path.
- This subsystem is the final step that turns latent speech representations into playable audio.
7. Text/model backbone subsystem
- src/voxcpm/modules/minicpm4/ contains the MiniCPM-4-based backbone integration.
- Files like config.py, model.py, and cache.py indicate standard LLM-style concerns: configuration, forward pass, and KV-cache/state handling for generation.
- This backbone is the part that converts normalized text and context into the intermediate conditioning sequence consumed by the speech generator.
8. Generation/control layers
- src/voxcpm/modules/locdit/local_dit.py, local_dit_v2.py, and unified_cfm.py implement the diffusion/flow-matching generation stage.
- src/voxcpm/modules/layers/lora.py shows LoRA is integrated at the model layer rather than as a separate training-only fork.
- scalar_quantization_layer.py suggests the repo also includes speech/token representation plumbing for compact latent handling.
- Together these modules define the controllable generation path used for voice design, cloning, and continuation-style synthesis.
9. Training subsystem
- src/voxcpm/training/ is a complete training stack with accelerator setup, configs, dataset loading, packing, state management, tracking, and validation.
- The main training script is scripts/train_voxcpm_finetune.py, which consumes the YAML configs in conf/.
- This stack supports the two finetuning modes called out in the README: full SFT and LoRA finetuning.
- The presence of validate.py and tracker.py suggests training is instrumented with periodic evaluation and experiment logging, rather than being a minimal one-off script.
10. Data flow for finetuning
- Example training data is stored in examples/train_data_example.jsonl, implying a line-delimited metadata format for audio/text supervision.
- src/voxcpm/training/data.py and packers.py are the likely boundary between raw manifest records and model-ready training batches.
- The flow is: dataset manifest → packing/normalization → training state/accelerator → model update → validation.
11. User-facing input/output helpers
- src/voxcpm/utils/text_normalize.py handles text preprocessing, which matters because the system supports many languages and likely needs normalization before synthesis.
- src/voxcpm/zipenhancer.py is a small utility module outside the main model stack; it looks like a packaging or archive helper, not a core inference component.
- examples/example.wav and examples/reference_speaker.wav serve as canonical reference assets for cloning and demo paths.
12. Testing and verification
- tests/ and scripts/test_*.py show the repo validates both the package API and the model behaviors.
- The test suite covers CLI behavior, model utilities, validation logic, LoRA checkpoint loading, and runtime dtype selection.
- That tells you the architecture has a clear separation between model correctness, CLI surface, and training/validation logic.
13. Packaging and release
- pyproject.toml, uv.lock, and .github/workflows/publish-to-pypi.yml show this is packaged for standard Python distribution and automated PyPI release.
- The repo is meant to be consumed as an installable library, but also ships runnable scripts and demo entry points.
- In architectural terms, that means the source tree is not just research code; it is structured for both library reuse and end-user execution.
14. Overall architecture shape
- The cleanest diagram is: UI/CLI/script entry points → core orchestration → versioned model wrappers → shared modules (MiniCPM backbone, local encoder, diffusion generator, AudioVAE, LoRA/quantization layers) → audio output.
- The training path shares the same model modules but swaps the source of inputs: instead of prompt-time text/reference audio, it consumes dataset manifests and validation loops.
- Version-specific YAML configs and examples keep the same codebase adaptable across VoxCPM generations without changing the public API.
Main entry points: voxcpm2.py VoxCPM2 · core.py Orchestrator · config.py Training stack · utils.py Model utils
Components 23
Entry points
User-facing CLI, web, and script entry points
- CLI · Command-line interface for design, clone, and batch flows
src/voxcpm/cli.py - Web demo · Main browser-based demo server
app.py - LoRA UI · Web UI for LoRA fine-tuning and inference
lora_ft_webui.py - Train script · Standalone finetuning runner
scripts/train_voxcpm_finetune.py - Inference checks · Standalone runtime and inference verification scripts
scripts/test_voxcpm_ft_infer.py
Library core
Public package surface and orchestration
- Package API · Library exports for external consumers
src/voxcpm/__init__.py - Orchestrator · Main inference orchestration across loading, generation, streaming, and voice modes
src/voxcpm/core.py
Model stack
Versioned model wrappers and shared generation modules
- VoxCPM · First-generation model wrapper
src/voxcpm/model/voxcpm.py - VoxCPM2 · Second-generation model wrapper
src/voxcpm/model/voxcpm2.py - Model utils · Common model helpers used across generations
src/voxcpm/model/utils.py - LocEnc · Speech context and local encoding stage
src/voxcpm/modules/locenc/local_encoder.py - MiniCPM-4 · Backbone language model integration with config, forward, and cache handling
src/voxcpm/modules/minicpm4/model.py - LocDiT · Diffusion / flow-matching latent speech generation
src/voxcpm/modules/locdit/local_dit_v2.py - CFM · Unified conditional flow-matching generation logic
src/voxcpm/modules/locdit/unified_cfm.py - AudioVAE · Latent audio encode/decode path and reconstruction interface
src/voxcpm/modules/audiovae/audio_vae_v2.py - LoRA · Low-rank adaptation support integrated at the model layer
src/voxcpm/modules/layers/lora.py - Quantization · Scalar quantization and latent token plumbing
src/voxcpm/modules/layers/scalar_quantization_layer.py
Training
Fine-tuning and validation pipeline
- Training stack · Accelerator, config, data, state, tracking, and validation
src/voxcpm/training/config.py - Validation · Training-time validation and evaluation logic
src/voxcpm/training/validate.py
Configs & examples
Versioned configs and example artifacts
- V1 configs · Versioned finetuning configs for VoxCPM v1
conf/voxcpm_v1/voxcpm_finetune_all.yaml - V1.5 configs · Versioned finetuning configs for VoxCPM v1.5
conf/voxcpm_v1.5/voxcpm_finetune_all.yaml - V2 configs · Versioned finetuning configs for VoxCPM v2
conf/voxcpm_v2/voxcpm_finetune_all.yaml - Train data · Example line-delimited training dataset manifest
examples/train_data_example.jsonl
Connections 24
- CLI → Orchestrator: inference · CLI routes generation requests into the orchestration layer
- Web demo → Orchestrator: demo inference · Web demo uses the same runtime core as the CLI
- LoRA UI → Orchestrator: lora inference · LoRA web UI drives the shared inference stack
- Package API → Orchestrator: exports · Public API re-exports the main runtime wrapper
- Orchestrator → VoxCPM: loads · Core can dispatch to first-generation model logic
- Orchestrator → VoxCPM2: loads · Core can dispatch to second-generation model logic
- VoxCPM → Model utils: shares · Version wrapper reuses common helpers
- VoxCPM2 → Model utils: shares · Version wrapper reuses common helpers
- VoxCPM2 → LocEnc: uses · VoxCPM2 passes context through the local encoder
- VoxCPM2 → MiniCPM-4: uses · VoxCPM2 relies on the MiniCPM-4 backbone
- VoxCPM2 → LocDiT: uses · VoxCPM2 generates speech latents with LocDiT
- VoxCPM2 → AudioVAE: uses · VoxCPM2 encodes and decodes audio through AudioVAE
- LocDiT → CFM: built on · LocDiT uses unified flow-matching generation logic
- VoxCPM2 → LoRA: adapts · LoRA adapters integrate into the model layer
- VoxCPM2 → Quantization: plumbs · Quantized latent handling supports generation and conditioning
- Train script → Training stack: invokes · Training entry point runs the training stack
- Training stack → Train data: reads · Training stack consumes manifest-style example data
- Training stack → V1 configs: configures · Training stack is driven by versioned YAML configs
- Training stack → V1.5 configs: configures · Training stack is driven by versioned YAML configs
- Training stack → V2 configs: configures · Training stack is driven by versioned YAML configs
- Training stack → Validation: includes · Training loop includes validation and evaluation
- Inference checks → Orchestrator: checks · Inference scripts verify runtime behavior through the core stack
- Inference checks → LoRA: checks · Runtime checks cover LoRA loading and inference
- CLI → Model utils: normalizes · User-facing flows depend on model-side helpers indirectly through the core