本模型基于 ModelScope iic/speech_sambert-hifigan_tts_zhiya_zh-cn_16k 完成昇腾 NPU 适配,支持在华为昇腾 Atlas 800 A2/A3 设备上进行中文语音合成推理。
本仓库提供完整的昇腾 NPU 推理脚本,支持在华为 Ascend910 系列 NPU 上直接运行该 TTS 模型。适配工作包括:
| 项目 | 版本/要求 |
|---|---|
| Python | >= 3.8 |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| NPU | Ascend910 |
| NumPy | >= 1.20 |
| PyYAML | >= 6.0 |
# 安装 PyTorch NPU
pip install torch==2.9.0 torch_npu==2.9.0.post1
# 安装其他依赖
pip install numpy pyyamlpip install modelscope
modelscope download --model iic/speech_sambert-hifigan_tts_zhiya_zh-cn_16k# 精度验证:CPU vs NPU 对比
python inference.py --mode validate
# 性能基准测试:NPU 推理性能
python inference.py --mode benchmark
# 端到端验证(精度 + 性能)
python inference.py --mode all
# 快速测试:CPU 前向传播
python inference.py --mode testfrom inference import load_models, run_inference
# 在 NPU 上加载模型
am, voc = load_models('npu:0')
# 运行推理,seq_len 控制合成文本长度
audio = run_inference(am, voc, seq_len=30, device='npu:0')
print(f"输出音频: {audio.shape}, {audio.size} 采样点")CPU (PyTorch) vs NPU (torch_npu) 输出精度对比:
| 序列长度 | CPU 采样点 | NPU 采样点 | 平均绝对误差 | 最大绝对误差 | 相对误差 |
|---|---|---|---|---|---|
| Short (15帧) | 6000 | 6000 | 2.90e-06 | 1.90e-05 | 0.000290% |
| Medium (30帧) | 12000 | 12000 | 3.03e-06 | 2.31e-05 | 0.000303% |
| Long (50帧) | 20000 | 20000 | 3.15e-06 | 2.16e-05 | 0.000315% |
在 Ascend910 上的推理性能(30帧固定序列):
| 指标 | 数值 |
|---|---|
| 设备 | Ascend910 (2 devices) |
| 预热次数 | 3 |
| 测试次数 | 10 |
| 平均推理时间 | 0.080s |
| 最小推理时间 | 0.032s |
| 最大推理时间 | 0.096s |
| 吞吐量 | 12.53 it/s |
SAMBert 将时长模型和声学模型联合建模:
基于 GAN 的生成器,使用多尺度判别器训练:
| 模块 | 参数量 |
|---|---|
| SAMBert 声学模型 | 12,332,651 |
| HifiGAN 声码器 | 4,866,001 |
| 总计 | 17,198,652 |
| 文件 | 说明 |
|---|---|
inference.py | 推理脚本(含 SAMBert + HifiGAN 完整实现) |
README.md | 部署文档(本文档) |
results_accuracy.json | 精度评测结果 |
results_benchmark.json | 性能基准测试结果 |
validation_log.txt | 精度验证运行日志 |
fusion_result.json | NPU 算子融合报告 |
@inproceedings{li2020robutrans,
title={Robutrans: A robust transformer-based text-to-speech model},
author={Li, Naihan and Liu, Yanqing and Wu, Yu and Liu, Shujie and Zhao, Sheng and Liu, Ming},
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
volume={34},
number={05},
pages={8228--8235},
year={2020}
}
@article{kong2020hifi,
title={Hifi-gan: Generative adversarial networks for efficient and high fidelity speech synthesis},
author={Kong, Jungil and Kim, Jaehyeon and Bae, Jaekyoung},
journal={Advances in Neural Information Processing Systems},
volume={33},
pages={17022--17033},
year={2020}
}Apache License 2.0