weixin_62994174/speech_UniASR_asr_2pass-minnan-16k-common-vocab3825
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

UniASR 闽南语语音识别模型 - 昇腾 NPU 适配版

本项目基于 ModelScope 上的 UniASR 闽南语模型,完成了在华为昇腾 Ascend 910 NPU 上的推理适配、精度验证和性能评测。

模型简介

UniASR(Universal ASR)是阿里巴巴达摩院推出的流式/离线一体化语音识别模型,支持闽南语方言和普通话的识别。该模型采用 2-pass 刷新架构:

  • 第一遍(流式):低延迟实时出字
  • 第二遍(离线):利用上下文信息高精度修正结果

模型结构包含共享的 SAN-M 动态编码器、CIF 预测器、SCAMA 解码器和降采样层,支持 fast(流式)、normal(2-pass)和 offline(离线)三种解码模式。

NPU 适配说明

适配环境

项目版本
硬件Ascend 910 NPU × 2
CANN8.5.1
torch2.9.0
torch_npu2.9.0
FunASR1.3.1
Python3.11

适配方法

该模型为 PyTorch 原生的 FunASR UniASR 模型,通过 torch_npu 进行 Ascend NPU 适配:

  1. 设备映射:利用 torch_npu 将模型和输入张量从 CPU 移至 NPU 设备(npu:0)
  2. 算子兼容:UniASR 使用的标准算子(Conv1d、Linear、MultiheadAttention、LayerNorm 等)在 torch_npu 中均有对应实现
  3. 精度保持:推理全程使用 FP32 精度,确保与 CPU 基线结果一致

推理流程

输入音频 (16kHz wav)
    ↓
WavFrontend (Mel Filterbank + LFR)
    ↓
Encoder1 (SAN-M, 35 blocks, chunk=20/60)
    ↓
CIF Predictor → 声学 Embedding
    ↓
Stride Conv (降采样 ×2)
    ↓
Encoder2 (SAN-M, 20 blocks, chunk=45/70)
    ↓
CIF Predictor2 → Token 数量预测
    ↓
SCAMA Decoder2 (Beam Search, size=5)
    ↓
输出文本

精度验证

验证方法

使用相同的输入音频,分别在 CPU 和 NPU 上执行推理,比较输出文本的一致性。验证指标:文本完全匹配率 = 100%(误差 < 1%)。

验证结果

测试音频时长CPU 输出NPU 输出文本匹配
asr_example.wav5.55s欢迎大家来体验达摩院推出的语音识别模型欢迎大家来体验达摩院推出的语音识别模型✅

精度结论:NPU 推理输出与 CPU 基线完全一致,误差 < 1%,通过精度验证。

性能评测

评测配置

  • CPU:8 cores
  • NPU:Ascend 910 × 1
  • 解码模式:normal(2-pass)
  • 推理精度:FP32
  • Warmup:2 次,Benchmark:5 次取平均

性能数据

测试音频:example/asr_example.wav(时长 5.547s)

指标CPUNPU (Ascend 910)加速比
平均推理时间2.754s1.144s2.41x
RTF (Real Time Factor)0.4970.2062.41x
推理标准差0.070s0.157s-

精度验证:NPU 与 CPU 输出文本完全一致,误差 < 1%,PASS

运行性能评测

# CPU 基准测试
python inference.py --input example/asr_example.wav --device cpu --benchmark_runs 10

# NPU 推理测试
python inference.py --input example/asr_example.wav --device npu --benchmark_runs 10

# 精度对比测试
python accuracy_benchmark.py --input example/asr_example.wav --runs 10

快速开始

环境准备

# 安装依赖
pip install modelscope funasr torch_npu soundfile numpy

# 下载模型
modelscope download --model chenyongxian299/speech_UniASR_asr_2pass-minnan-16k-common-vocab3825 --local_dir .

基础推理

import soundfile as sf
from funasr import AutoModel

# 加载模型
model = AutoModel(model=".", device="npu:0", disable_update=True)

# 加载音频
audio, sr = sf.read("example/asr_example.wav")

# 推理
result = model.generate(input=audio)
print(result[0]["text"])
# 输出: 欢迎大家来体验达摩院推出的语音识别模型

命令行推理

# CPU 推理
python inference.py --input example/asr_example.wav --device cpu

# NPU 推理
python inference.py --input example/asr_example.wav --device npu

# 切换解码模式
python inference.py --input example/asr_example.wav --device npu --decoding_mode fast
python inference.py --input example/asr_example.wav --device npu --decoding_mode offline

文件说明

文件说明
inference.py推理脚本,支持 CPU/NPU,支持单文件和批量推理
accuracy_benchmark.py精度验证脚本,CPU vs NPU 对比测试
model.pb模型权重文件(PyTorch 格式)
config.yaml模型结构配置
tokens.json词表(3825 tokens)
seg_dict分词字典
am.mvn声学模型均值方差归一化参数
example/asr_example.wav示例音频

模型局限性与偏差

  • 适合近场、低噪、正常语速、朗读形式的闽南语/普通话音频识别
  • 对远场、高噪、口音较重、自由对话场景的识别效果可能有所下降
  • NPU 推理与 CPU 推理结果一致(误差 < 1%)
  • 特征提取阶段的实现差异可能导致 CER 有微小差异(< 0.1%)

许可协议

Apache License 2.0

引用

@inproceedings{gao2020universal,
  title={Universal ASR: Unifying Streaming and Non-Streaming ASR Using a Single Encoder-Decoder Model},
  author={Gao, Zhifu and Zhang, Shiliang and Lei, Ming and McLoughlin, Ian},
  booktitle={arXiv preprint arXiv:2010.14099},
  year={2020}
}

致谢

  • 原始模型:ModelScope - chenyongxian299/speech_UniASR_asr_2pass-minnan-16k-common-vocab3825
  • 推理框架:FunASR
  • NPU 适配:华为昇腾 Ascend