本仓库包含gomodels/sherpa的昇腾NPU适配版本,集成了两个最先进的语音模型:
| 模型 | 任务 | 架构 | 后端 |
|---|---|---|---|
| SenseVoice | 语音识别(ASR) | CTC Transformer | ONNX Runtime + torch_npu |
| Matcha-TTS | 文本转语音(TTS) | Flow Matching + Vocos | ONNX Runtime + torch_npu |
NPU适配采用混合加速架构:
| 任务 | 指标 | 结果 | 阈值 | 状态 |
|---|---|---|---|---|
| ASR(SenseVoice) | 文本匹配 | 100%匹配 | 完全匹配 | 通过 |
| TTS(Matcha-TTS) | NRMSE | 0.0000% | < 1% | 通过 |
| TTS(Matcha-TTS) | 相关性 | 1.0000 | > 0.99 | 通过 |
| 任务 | 设备 | 平均时间(秒) | RTF | 速度(实时倍数) |
|---|---|---|---|---|
| ASR(5.6秒音频) | CPU | 0.288 | 0.052 | 19.4倍 |
| ASR(5.6秒音频) | NPU | 0.275 | 0.049 | 20.3倍 |
| TTS(4.1秒输出) | CPU | 0.260 | 0.064 | 15.7倍 |
| TTS(4.1秒输出) | NPU | 0.274 | 0.067 | 14.9倍 |
# Install dependencies
pip install sherpa-onnx onnxruntime onnx soundfile numpy librosa
# Ascend NPU dependencies (pre-installed on Ascend servers)
# torch_npu, CANN toolkitpip install modelscope
modelscope download --model gomodels/sherpa语音识别(ASR):
# CPU mode
python inference.py --task asr --input audio.wav --device cpu
# NPU mode
python inference.py --task asr --input audio.wav --device npu
# Test with included sample
python inference.py --task asr \
--input ~/.cache/modelscope/hub/models/gomodels/sherpa/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/test_wavs/zh.wav \
--device npu文本转语音(TTS):
# CPU mode
python inference.py --task tts --input "你好世界" --output output.wav --device cpu
# NPU mode
python inference.py --task tts --input "你好世界" --output output.wav --device npu准确性验证:
python inference.py --task validate性能基准测试:
# CPU + NPU comparison
python benchmark.py --task all --runs 5 --device bothsherpa-npu/
├── inference.py # Main inference script (ASR + TTS, CPU + NPU)
├── npu_tts.py # NPU-accelerated TTS with PyTorch weights
├── benchmark.py # Performance benchmarking script
├── README.md # This documentation
├── requirements.txt # Python dependencies
└── results/ # Evaluation results
├── accuracy_validation.json
└── benchmark.jsonApache License 2.0