# VoxCPM2 voice-cloning backend A local voice-cloning tool (reference-clip-based cloning) for owned or consented voices. Keep this separate from `local-ema-backend.md` — EMA Lightning does plain narration only and has no cloning capability at all; do not conflate the two when asked "how did we clone a voice." ## Install (standalone — do not go through VoiceStudio) ```bash pip install voxcpm ``` This is OpenBMB's own PyPI package, independent of any GUI wrapper. Requirements: Python >=3.10,<3.13, PyTorch >=2.5.0. Device selection is automatic (`cuda -> mps -> cpu`) unless forced with `device="cpu"/"mps"/"cuda"`. ## License separation — the one thing to get right - **VoxCPM2 itself (OpenBMB/VoxCPM) is Apache-2.0** — weights and code, free for commercial use, safe to depend on directly in any new project including public open-source repos. - **VoiceStudio (debpalash/VoiceStudio)** — a GUI wrapper that can also run VoxCPM2 — **is AGPL-3.0**, a copyleft license. - When building anything new (especially a public GitHub repo) that needs VoxCPM2's capability: use the standalone `pip install voxcpm` package directly. Never copy code from the VoiceStudio checkout or depend on its backend server — that pulls AGPL obligations into a project that doesn't need them. The two licenses are legitimately different even when the same model is reachable through both paths. - The VoxCPM2 model card requires an "AI-generated" disclosure label on distributed output — carry this into any README/UI that produces audio with it. ## API Plain generation (no cloning, model designs its own voice): ```python from voxcpm import VoxCPM import soundfile as sf model = VoxCPM.from_pretrained("openbmb/VoxCPM2", load_denoiser=False) wav = model.generate(text="...", cfg_value=2.0, inference_timesteps=10, seed=42) sf.write("out.wav", wav, model.tts_model.sample_rate) ``` Cloning via CLI (confirmed working pattern): ```bash voxcpm clone --text "..." --reference-audio path/to/voice.wav --output out.wav --denoise ``` Confirmed Python-API equivalent (verified against the installed package source, not guessed): ```python model = VoxCPM.from_pretrained(hf_model_id="openbmb/VoxCPM2", load_denoiser=False, optimize=False) wav = model.generate(text="...", reference_wav_path="path/to/voice.wav", cfg_value=2.0, inference_timesteps=10) ``` The cloning kwarg is `reference_wav_path` (a bare reference clip, no transcript needed for this mode) — not `prompt_wav_path`. `from_pretrained` takes `hf_model_id=` as a named kwarg; `optimize=False` also skips the warm-up compile step, useful for a UI that must open fast and only load the model on first real request. ## Building a local-first Gradio wrapper around it (reusable pattern) - Set `os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"` and `os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"` **before** importing `gradio`/`voxcpm` — these read the env at import time, so setting them after import is a no-op. - Lazy-load the model (module-level `None` + a `threading.Lock`, loaded on first request) so the UI opens instantly without forcing a multi-GB download/load before anyone has clicked anything. - Serialize generation with the same lock plus `demo.queue(default_concurrency_limit=1)` — this model cannot usefully serve two concurrent requests on a single consumer machine; let Gradio queue them instead of racing/OOMing. - Bind `server_name="127.0.0.1", share=False` for a tool meant to stay local — no public tunnel by default. - Real end-to-end timing through this wrapper on the M1/16GB test machine (cold model load + generation, not just inference RTF): ~206s for a referenceless short sentence, ~128s for reference-clip cloning. Quote end-to-end numbers like these (not just RTF) when telling a user what to expect from a UI, since cold load time dominates the first request. Two cloning modes exist: - **Reference-only + style instruction** — flexible (can steer emotion/pace) but measurably degrades voice-identity similarity (real test: ECAPA similarity dropped from ~0.80 to 0.21-0.58 when a style instruction was added). - **"Continuation" mode** (reference audio + its transcript, no style instruction) — most reliable for preserving the original voice's identity (real test: ECAPA similarity 0.78-0.84). Prefer this mode whenever identity fidelity matters more than expressive control. ## Hardware reality (measured on an M1, 16GB RAM) - Model download alone ~5GB; full project disk footprint ~17-19GB. - RAM usage ~9GB during inference on Apple Silicon (MPS). - RTF (real-time factor) ~7-8 normally — i.e. SLOWER than real time (a 10s clip takes ~70-80s to generate), not the "instant" experience a lighter TTS model gives. - If available RAM is insufficient (e.g. an 8GB Mac, very common on base-model M1 Airs/Pros), the process swaps and RTF can degrade to 40-100x — near-unusable. This is a RAM-tier problem, not a chip-generation problem: any Apple Silicon chip (M1 and up) handles it architecturally fine with enough RAM. - Nvidia GPU is not required (MPS/CPU both work) but this is not a "try it in two minutes on any laptop" tool — state the RAM requirement honestly (16GB+ recommended) in any README or user-facing doc before distributing a wrapper around it. - Turkish text needs diacritic normalization (â/î/û → a/i/u) before synthesis for reliable output.