Chatterbox 是 ResembleAI 开源的 0.5B 参数级 TTS(文本转语音)模型,支持零样本语音克隆、情感夸张控制与 CFG 引导。模型由多组件构成:
conds.pt 预置参考音色条件原始模型:ResembleAI/chatterbox(MIT)
官方代码:resemble-ai/chatterbox(pip install chatterbox-tts,本仓库验证 0.1.7 可用)
适配方案(确定性对比路径):完整 TTS 生成链路(T3 多步采样 + S3Gen 合成)含随机采样与水印,跨端复现不稳定。本仓库采用 T3 teacher-forcing 前向:固定英文文本经 tokenizer 编码(含 BOT/EOT),拼接固定种子(42)的合成语音 token 序列(128 个),一次前向得到 text/speech logits,双端对比 cos_sim 与 argmax 一致率——完整验证加载路径与 transformer 计算图,输入完全一致、结果可复现。
依赖注意:chatterbox-tts 0.1.7 需补装 perth / s3tokenizer / conformer;perth ≥1.0 将水印类改名(
PerthImplicitWatermarker→Perth),inference.py 内置兼容别名(水印仅generate()路径使用,不影响本对比路径)。
# 1. 克隆仓库
git clone https://gitcode.com/weasonlee/chatterbox.git
cd chatterbox
# 2. 安装依赖
pip install -r requirements.txt
# 3. 下载权重到 models/(已 .gitignore 排除;全量约 12GB,
# 核心文件 ve/t3_cfg/s3gen.safetensors + tokenizer.json + conds.pt)
mkdir -p models
HF_ENDPOINT=https://hf-mirror.com HF_HUB_DOWNLOAD_TIMEOUT=120 python -c "
from huggingface_hub import snapshot_download
snapshot_download('ResembleAI/chatterbox', local_dir='models',
allow_patterns=['ve.safetensors','t3_cfg.safetensors',
's3gen.safetensors','tokenizer.json','conds.pt'])"
# 4. 推理(NPU,T3 teacher-forcing 对比路径)
python inference.py --device npu
# 或 CPU
python inference.py --device cpu$ python inference.py --device npu
torch.npu.is_available() = True
torch.npu.device_count() = 2
[info] device = npu:0, torch = 2.9.0+cpu
[load] T3 transformer: 532.4M params (+ S3Gen/voice-encoder components)
[info] text = 'Ascend NPU brings this voice model to life.'
[info] text_tokens = (1, 31), speech_tokens = (1, 128) (synthetic, seed=42)
[time] run 0: 31 ms
[time] avg: 30 ms (T3 teacher-forcing pass)
[out ] speech_logits: shape=(1, 128, 8194) mean=-2.2974 std=3.2404
[out ] text_logits: shape=(1, 31, 704) mean=-7.3950 std=5.2702
[out ] speech argmax sample: [3677, 5020, 1724, 6486, 737, 3413, 6377, 1735]
===== CPU vs NPU comparison (T3 teacher-forcing logits) =====
speech_logits cos_sim=0.99999998 max_abs_err=3.922e-03 mean_abs_err=5.157e-04 argmax_agree=99.22%
text_logits cos_sim=0.99999998 max_abs_err=7.683e-03 mean_abs_err=1.303e-03 argmax_agree=100.00%输入:固定英文文本("Ascend NPU brings this voice model to life.")+ 固定种子(42)合成语音 token(128 个,词表 6561)+ 内置 conds.pt 参考条件;CPU 与 NPU 输入完全一致。
| 输出 | cos_sim | max_abs_err | mean_abs_err | argmax 一致率 |
|---|---|---|---|---|
| speech_logits(128×8194) | 0.99999998 | 3.922e-03 | 5.157e-04 | 99.22% |
| text_logits(31×704) | 0.99999998 | 7.683e-03 | 1.303e-03 | 100.00% |
| 单次前向耗时(含同步,3 次均值) | NPU ~30 ms vs CPU ~3700 ms(~123× 加速) | — | — | — |
说明:speech_logits 的 argmax 一致率 99.22% 对应 128 个 token 中 1 个在 logits 差异 4e-3 量级下翻转(双端 logits 均为近并列值),cos_sim 仍达 0.99999998,计算图双端一致。fp32 正常差异水平,适配成功。
├── inference.py # 推理脚本(T3 teacher-forcing + NPU/CPU 对比)
├── readme.md
├── requirements.txt
├── models/ # 权重目录(需自行下载,已 gitignore)
├── assets/ # 运行截图
│ ├── agent_workflow.png
│ ├── npu_device_call.png
│ └── model_result.png
└── results/ # 每次运行的 logits/耗时产物(gitignore)Resemble AI. "Chatterbox: Open-Source TTS with Emotion and Voice Cloning." 2025. https://github.com/resemble-ai/chatterbox