OmniVoice 是大规模多语言零样本 TTS(文生语音)扩散模型,覆盖 600+ 种语言,由 k2-fsa (Xiaomi AI Lab) 开发。本项目提供模型在华为昇腾 Ascend 910 NPU 上的推理适配方案。
| 组件 | 版本 |
|---|---|
| CANN | 8.5.1 |
| torch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| transformers | >= 5.3.0 (5.10.2 测试通过) |
| omnivoice | 0.1.5 |
| Python | 3.11 |
# 1. 安装 OmniVoice 核心包
pip install omnivoice
# 2. 确保 transformers >= 5.3.0
pip install 'transformers>=5.3.0'
# 3. 下载模型权重
python -c "
from modelscope import snapshot_download
snapshot_download('k2-fsa/OmniVoice', cache_dir='/tmp/models/OmniVoice')
"
# 4. 设置 NPU 环境变量
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export ASCEND_RUNTIME_OPTIONS=task_queue_enable:1# 1. 构建镜像
bash docker_build.sh
# 2. 准备模型目录(首次运行自动下载)
mkdir -p /tmp/models
# 3. 运行推理
bash docker_run.sh --text "Hello world" --output /tmp/test.wav
# 自定义模型路径和 NPU 设备
OMNI_MODEL_DIR=/data/models OMNI_NPU_DEVICE=1 bash docker_run.sh --text "你好世界"
# Voice Design
bash docker_run.sh --text "Hello" --instruct "female, low pitch, british accent"# Auto Voice(无参考音频)
python omnivoice_npu_infer.py \
--model /tmp/models/OmniVoice/k2-fsa/OmniVoice \
--text "Hello world, this is OmniVoice on Ascend NPU." \
--output output.wav
# 中文合成
python omnivoice_npu_infer.py \
--text "你好世界,这是昇腾NPU上的语音合成。" \
--output zh.wav
# 快速模式(8步)
python omnivoice_npu_infer.py \
--text "Quick test." \
--num_step 8 \
--output fast.wav
# Voice Design
python omnivoice_npu_infer.py \
--text "Hello" \
--instruct "female, low pitch, british accent" \
--output design.wavfrom omnivoice_npu_infer import OmniVoiceNPU
engine = OmniVoiceNPU("/tmp/models/OmniVoice/k2-fsa/OmniVoice")
audio = engine.generate(
text="Hello world.",
num_step=32,
guidance_scale=2.0,
)
engine.save(audio, "output.wav")torch_npu 运行torch.rand_like 警告: NPU 上创建随机张量使用 base format 而非 internal format,不影响功能,是 torch_npu 已知行为| 维度 | 结果 | 数据 |
|---|---|---|
| 数值精度 | ✅ 通过 | CPU fp32 vs NPU fp16 Logits 余弦相似度 0.9992 |
| 功能完整性 | ✅ 通过 | Auto Voice / Voice Design / 多语言 (7种) / 长文本 (44s) / Non-verbal tags |
| 内存稳定性 | ✅ 通过 | 连续 5 次推理,HBM 增长 0%,1.91 GB |
| 音频有效性 | ✅ 通过 | 全部输出无 NaN/Inf,幅值范围 [-0.5, 0.5] |
| 性能 (RTF) | ✅ 通过 | 长文本 28.7x 实速,短文本 3.6-5.5x |
详细测试报告见 test_report.md。