weixin_62994174/sherpa-onnx-sense-voice-small
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

sherpa-onnx-sense-voice-small NPU

Hardware: Ascend NPU CANN 8.5.1 #NPU License

SenseVoice-small 语音识别模型在华为昇腾 NPU 上的适配与评测

基于 sherpa-onnx-sense-voice-small 模型,使用 FunASR + torch_npu 在昇腾 Atlas 800 A2 (Ascend 910B) NPU 上完成推理适配,实现 100% 精度对齐 与 14.66x 推理加速。


模型简介

项目说明
模型名称sherpa-onnx-sense-voice-small (SenseVoice-small)
任务类型自动语音识别 (ASR) / 多语种识别
原始模型iic/SenseVoiceSmall
导出格式ONNX (Opset 13) / PyTorch
参数规模~234M
采样率16kHz
支持语种中文、英文、粤语、日语、韩语(自动检测)
功能特性语音识别 + 语种检测 + 情感识别 + 音频事件检测 + 逆文本正则化 (ITN)
硬件标签#NPU #Ascend #Hardware-NPU

硬件要求

硬件规格
NPU 型号Ascend 910B (Atlas 800 A2)
HBM 显存64 GB
CANN 版本8.5.1
驱动版本25.5.2
Python3.11

环境配置

依赖安装

# 基础 PyTorch + NPU
pip install torch==2.9.0 torch_npu==2.9.0.post1

# 推理框架
pip install funasr>=1.3.1

# 音频处理
pip install soundfile librosa

# ONNX 模型分析(可选)
pip install onnx onnxruntime

模型下载

# 下载 sherpa-onnx 导出模型
pip install modelscope
modelscope download --model xiaowangge/sherpa-onnx-sense-voice-small

# 下载原始 SenseVoiceSmall 模型(NPU 推理用)
modelscope download --model iic/SenseVoiceSmall

快速开始

1. CPU 基准推理

python inference.py --backend cpu --wav morning_scene.wav

2. NPU 推理

python inference.py --backend npu --wav morning_scene.wav

3. 双端推理 + 精度验证

python inference.py --backend both --wav morning_scene.wav

推理示例

import numpy as np
import soundfile as sf
from funasr import AutoModel

# 加载模型到 NPU
model = AutoModel(
    model="iic/SenseVoiceSmall",
    device="npu:0",
    disable_update=True,
)

# 加载音频并推理
audio, sr = sf.read("morning_scene.wav")
result = model.generate(input=audio, language="auto", use_itn=True)
print(result[0]["text"])
# 输出: <|zh|><|NEUTRAL|><|Speech|><|withitn|>清晨的阳光透过薄雾...

精度评测

评测方法

在相同输入音频 morning_scene.wav(16kHz, 12.5s 中文语音)上,对比 CPU (PyTorch CPU) 与 NPU (Ascend 910B torch_npu) 的输出结果。

评测结果

指标结果说明
字符准确率100.00%NPU 与 CPU 输出完全一致
单词准确率100.00%Token 级完全对齐
字错率 (CER)0.00%编辑距离为 0
原始文本匹配True含标签的完整文本一致
误差率0.0000%通过(阈值 < 1%)

推理输出对比

CPU输出: <|zh|><|NEUTRAL|><|Speech|><|withitn|>清晨的阳光透过薄雾,在湖面洒下细碎的金斑,岸边的垂柳将绿丝绦垂进水里,引得几条小鱼,不时探出脑袋,搅碎满池倒影。
NPU输出: <|zh|><|NEUTRAL|><|Speech|><|withitn|>清晨的阳光透过薄雾,在湖面洒下细碎的金斑,岸边的垂柳将绿丝绦垂进水里,引得几条小鱼,不时探出脑袋,搅碎满池倒影。

性能评测

指标CPU (PyTorch)NPU (Ascend 910B)加速比
推理耗时1.832 s0.125 s14.66x
RTF (Real Time Factor)0.1470.010-

测试条件:输入音频时长 12.5s @ 16kHz,包含 warmup 后的单次推理。


适配技术说明

NPU 适配方案

选用 FunASR + torch_npu 方案,直接加载 PyTorch 版 SenseVoiceSmall 模型到昇腾 NPU:

音频输入 (soundfile)
    ↓
FunASR AutoModel (SenseVoiceSmall)
    ↓
torch_npu → Ascend 910B NPU
    ↓
CTC/Attention Decoder
    ↓
文本输出 (含语种/情感/事件标签)

关键技术点

  1. 模型加载:使用 AutoModel(model=local_path, device="npu:0") 加载本地模型到 NPU
  2. 音频加载:使用 soundfile 替代 ffmpeg/torchcodec 加载音频(避免缺失依赖)
  3. 精度对齐:PyTorch NPU 后端 (torch_npu) 使用与 CPU 相同的 FP32 精度,保证 100% 输出一致
  4. 内存优化:设置 PYTORCH_NPU_ALLOC_CONF=expandable_segments:True 启用显存动态扩展

文件说明

sherpa-onnx-sense-voice-small/
├── inference.py          # NPU 推理与评测脚本
├── README.md             # 本文件 - 模型适配文档
├── eval_results.json     # 评测结果 JSON
├── model.onnx            # ONNX 模型 (FP32, 894MB)
├── model_q8.onnx         # ONNX 模型 (INT8, 228MB)
├── tokens.txt            # 词表 (25055 tokens)
├── config.json           # sherpa-onnx 配置
├── morning_scene.wav     # 测试音频 (12.5s, 中文)
├── morning_scene.mp3     # 测试音频 (mp3)
├── silero-vad/           # VAD 模型
├── ws_client.py          # WebSocket 客户端
└── http_ws_server.py     # HTTP/WS 服务端

运行日志

======================================================================
sherpa-onnx-sense-voice-small Ascend NPU Adaptation
Model: /opt/atomgit/.cache/modelscope/hub/models/iic/SenseVoiceSmall
Date: 2026-05-16
======================================================================

>>> CPU Baseline Inference
[CPU] Model device: cpu
[CPU] Inference time: 1.832s
[CPU] Output: <|zh|><|NEUTRAL|><|Speech|><|withitn|>清晨的阳光透过薄雾...

>>> NPU Inference (Ascend 910B)
[NPU] Model device: npu:0
[NPU] Inference time: 0.125s
[NPU] Output: <|zh|><|NEUTRAL|><|Speech|><|withitn|>清晨的阳光透过薄雾...

======================================================================
ACCURACY VERIFICATION
======================================================================
Character Accuracy:    100.00%
Word Accuracy:         100.00%
Edit Distance (CER):   0.00%
Error Rate:            0.0000%
NPU vs CPU Speedup:    14.66x
Verification:          PASSED (threshold: < 1% error)
======================================================================

许可

本项目基于 Apache 2.0 许可开源。原始 SenseVoice 模型版权归阿里巴巴通义实验室所有。


引用

  • SenseVoice 原始模型: https://github.com/FunAudioLLM/SenseVoice
  • sherpa-onnx: https://github.com/k2-fsa/sherpa-onnx
  • FunASR: https://github.com/modelscope/FunASR
  • 华为昇腾: https://www.hiascend.com/
  • ModelScope: https://www.modelscope.cn/models/iic/SenseVoiceSmall

本仓库由 Model Agent 于 2026-05-16 在华为昇腾 NPU (Ascend 910B) 上完成适配与评测。