ResembleAI/chatterbox 文本转语音(TTS)模型的 昇腾 NPU (Ascend 910 / torch-npu) 适配工程。
ChatterboxTTS,0.5B Llama backbone + S3Gen 声码器)npu:0(ASCEND_VISIBLE_DEVICES=12)python inference.py --text "合成文本"(兼容 --img 别名)uvicorn inference:app --host 0.0.0.0 --port 8000,POST /predict 接收 {"text": "..."},返回 wav 路径 / base64 / 时长 / 采样率等 JSON。conds.pt),开箱即用,无需参考音频。| 组件 | 版本 |
|---|---|
| 硬件 | Ascend 910(≥1 卡) |
| CANN | ≥ 8.0(本机 8.5.1) |
| Python | 3.10 / 3.11 |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install -r requirements.txt权重缓存于 ./model_weights/chatterbox(本地优先,非空直接复用)。
export HF_ENDPOINT=https://hf-mirror.com
python -c "
from huggingface_hub import snapshot_download
snapshot_download('ResembleAI/chatterbox', local_dir='./model_weights/chatterbox',
allow_patterns=['ve.safetensors','t3_cfg.safetensors','s3gen.safetensors','tokenizer.json','conds.pt','README.md'])
"export ASCEND_VISIBLE_DEVICES=12
python inference.py --text "Hello, this is a test of the chatterbox text to speech model running on Ascend NPU."输出 JSON(含 wav_path、base64_wav、duration_s、sample_rate 等),合成 wav 保存于工程目录 output.wav。
export ASCEND_VISIBLE_DEVICES=12
uvicorn inference:app --host 0.0.0.0 --port 8000 &
curl -X POST http://127.0.0.1:8000/predict \
-H 'Content-Type: application/json' \
-d '{"text": "Hello, this is a test of the chatterbox text to speech model running on Ascend NPU."}'| 文件 | 说明 |
|---|---|
inference.py | 双模式推理脚本(CLI + FastAPI) |
requirements.txt | NPU 运行依赖 |
model_weights/chatterbox/ | 本地权重缓存 |
assets/agent_workflow.png | NPU 部署安装日志截图 |
assets/npu_device_call.png | CLI 推理成功截图 |
assets/model_result.png | FastAPI 返回 JSON 截图 |
import torch_npu + torch.npu.set_device(0) + DEVICE="npu:0",try-except 捕获 NPU 初始化异常。npu:0,全域零 CUDA 语句。ChatterboxTTS.from_local 加载权重(safetensors 加载到 CPU 后 .to("npu:0"))。perth 为纯 numpy 实现,CPU 运行,不依赖 GPU。