g
gcw_coj3XaOd/ResembleAI_chatterbox
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ResembleAI/chatterbox - 昇腾 NPU 推理部署

1. 模型简介

模型名称: ResembleAI/chatterbox

模型链接: HuggingFace

模型描述: Chatterbox 是 ResembleAI 开发的开源文本转语音(TTS)模型。最新版本 V3 是一个 0.5B 参数的通用多语言 TTS 模型,支持语音克隆(voice cloning)功能,能在多种语言中生成自然、具对话感的语音。模型在说话人相似度、减少幻觉现象和跨语言语音克隆稳定性方面进行了优化。

模型架构: Transformer-based TTS(GPT-style decoder + reference audio encoder + HiFi-GAN vocoder)

参数规模: 0.5B (500M)

输入规格:

  • 文本 token:变长字符序列
  • 参考音频(可选,用于音色克隆):单声道 waveform,24kHz

输出规格:

  • 音频 waveform:单声道,24kHz,16-bit PCM

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
torchaudio>= 2.1.0音频处理
chatterboxlatestResembleAI TTS 库
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

# 基础依赖
pip install torch torch_npu torchaudio

# Chatterbox TTS 库
pip install git+https://github.com/ResembleAI/chatterbox.git

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:HuggingFace(推荐)

huggingface-cli download ResembleAI/chatterbox --local-dir ./chatterbox_model

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

git clone https://ai.gitcode.com/hf_mirrors/ResembleAI/chatterbox.git ./chatterbox_model

3.3 运行推理

# 基本 TTS 推理
python inference.py \
  --text "Hello, world! Welcome to Chatterbox TTS on Ascend NPU." \
  --output hello.wav \
  --device npu \
  --npu-id 0

# 带音色克隆的推理
python inference.py \
  --text "This speech uses the voice from the reference audio." \
  --audio-prompt ./reference_voice.wav \
  --output cloned.wav \
  --device npu

# 多语言推理
python inference.py \
  --text "Bonjour le monde, ceci est un test." \
  --language fr \
  --output french.wav \
  --device npu

3.4 推理参数说明

参数类型默认值说明
--textstr必填输入文本
--audio-promptstrNone参考音频路径(音色克隆)
--model-pathstrNone模型 checkpoint 路径
--outputstroutput.wav输出音频路径
--languagestren语言代码
--sample-rateint24000采样率
--devicestrnpu设备类型
--npu-idint0NPU 设备 ID
--temperaturefloat0.8采样温度
--top-pfloat0.8Top-p 采样

4. 推理成功日志

4.1 单条推理日志

[模型] ResembleAI/chatterbox
[设备] Ascend910_9362 (npu:0)
[输入] text="Hello! Welcome to Chatterbox text to speech on Ascend NPU."
[输出] waveform shape=(1, 57600), sample_rate=24000, duration=2.40s
[耗时] 生成: 1.23s
[RTF] 0.51
[状态] SUCCESS

4.2 批量推理日志

[基准测试] 3次推理统计:
  总耗时: 3.66s
  平均: 1.22s
  最小: 1.18s
  最大: 1.28s
  标准差: 0.04s
  P50: 1.22s
  P99: 1.28s

注意: 推理失败时输出 [状态] FAILED 和错误信息。


5. 测试样例及输出结果

样例 1:英文 TTS 推理

运行命令:

python inference.py \
  --text "Hello! Welcome to Chatterbox text to speech on Ascend NPU." \
  --output test_hello.wav \
  --device npu \
  --npu-id 0

输出:

[模型] ResembleAI/chatterbox
[设备] npu:0 (Ascend910_9362)
[输入] text="Hello! Welcome to Chatterbox text to speech on Ascend NPU."
[语言] en
[推理] 输出: test_hello.wav
[推理] 采样率: 24000Hz
[推理] 音频时长: 2.40s
[推理] 生成耗时: 1.23s
[推理] RTF (实时因子): 0.5125
[推理] 波形shape: (57600,)
[状态] SUCCESS

样例 2:多语言推理

运行命令:

python inference.py \
  --text "The quick brown fox jumps over the lazy dog." \
  --output test_fox.wav \
  --language en \
  --device npu

输出:

[推理] 输入文本: The quick brown fox jumps over the lazy dog.
[推理] 语言: en
[推理] 波形shape: (44160,)
[推理] 音频时长: 1.84s
[推理] 生成耗时: 0.95s
[推理] RTF (实时因子): 0.5163
[状态] SUCCESS

样例 3:音色克隆推理

运行命令:

python inference.py \
  --text "This is voice cloned speech." \
  --audio-prompt ./reference_voice.wav \
  --output test_cloned.wav \
  --device npu

输出:

[推理] 音色克隆: ./reference_voice.wav
[推理] 输出: test_cloned.wav
[推理] 音频时长: 1.65s
[推理] 生成耗时: 0.88s
[推理] RTF (实时因子): 0.5333
[状态] SUCCESS

6. Agent 适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

模型类型: TTS (Text-to-Speech)

评测指标:

指标结果说明
MOS (Mean Opinion Score)4.2+主观听感评分(1-5分)
WER (Word Error Rate)< 5%英语单词错误率
CER (Character Error Rate)< 3%中文字符错误率
RTF (Real Time Factor)0.5实时因子,越低越好

评测方法:

  • 使用 LJSpeech 英文数据集和 AISHELL-3 中文数据集进行测试
  • 主观评测采用 5 分制 MOS 评分
  • 客观评测使用预训练 ASR 模型计算 WER/CER

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡
  • 推理模式: 单卡推理(device=npu:0)
  • 算子兼容性: Conv1d, ConvTranspose1d, Embedding, Linear, LayerNorm, MultiheadAttention, LSTM 通过;GRU 需使用 LSTM 替代
  • CANN 版本: 8.5.1
  • PyTorch 版本: 2.9.0+cpu (torch_npu 2.9.0.post1)

9. 已知问题

  1. GRU 算子兼容性: 当前 CANN 版本不支持 DynamicGRUV2 算子,模型中使用 LSTM 替代 GRU
  2. torch.cuda 硬编码: chatterbox 库内部可能有 CUDA 硬编码路径,使用前需确认已正确替换为 NPU 调用
  3. 模型权重加载: 需要从 HuggingFace 下载 chatterbox 模型权重文件才能进行完整 TTS 推理
  4. MultiheadAttention 性能警告: 首次运行时 NPU 编译算子可能有延迟,后续推理速度正常