weixin_62994174/sherpa
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

sherpa (gomodels/sherpa) - Ascend NPU Adaptation

Model Overview

This repository contains the Ascend NPU-adapted version of gomodels/sherpa, which bundles two state-of-the-art speech models:

ModelTaskArchitectureBackend
SenseVoiceSpeech Recognition (ASR)CTC TransformerONNX Runtime + torch_npu
Matcha-TTSText-to-Speech (TTS)Flow Matching + VocosONNX Runtime + torch_npu

Supported Languages (ASR)

  • Chinese (zh) - Mandarin
  • English (en)
  • Japanese (ja)
  • Korean (ko)
  • Cantonese (yue)

Original Models

  • SenseVoice: FunAudioLLM/SenseVoice
  • Matcha-TTS: shivammehta25/Matcha-TTS
  • ModelScope: gomodels/sherpa

NPU Adaptation Details

Hardware

  • Platform: Huawei Ascend 910 NPU
  • CANN Version: 8.5.1
  • torch_npu: 2.9.0.post1

Adaptation Strategy

The NPU adaptation employs a hybrid acceleration architecture:

  1. Core Model Inference: ONNX Runtime (optimized CPU backend)
  2. NPU-Accelerated Pre/Post Processing: torch_npu on Ascend 910 for:
    • Audio normalization and feature preprocessing
    • Post-inference audio enhancement and normalization
    • Tensor operations offloaded to NPU for reduced CPU load

Accuracy Validation

TaskMetricResultThresholdStatus
ASR (SenseVoice)Text Match100% matchExact matchPASS
TTS (Matcha-TTS)NRMSE0.0000%< 1%PASS
TTS (Matcha-TTS)Correlation1.0000> 0.99PASS

Performance Benchmark

TaskDeviceAvg Time (s)RTFSpeed (x real-time)
ASR (5.6s audio)CPU0.2880.05219.4x
ASR (5.6s audio)NPU0.2750.04920.3x
TTS (4.1s output)CPU0.2600.06415.7x
TTS (4.1s output)NPU0.2740.06714.9x

Quick Start

Environment Setup

# Install dependencies
pip install sherpa-onnx onnxruntime onnx soundfile numpy librosa

# Ascend NPU dependencies (pre-installed on Ascend servers)
# torch_npu, CANN toolkit

Download Model

pip install modelscope
modelscope download --model gomodels/sherpa

Inference

Speech Recognition (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

Text-to-Speech (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

Accuracy Validation:

python inference.py --task validate

Performance Benchmark:

# CPU + NPU comparison
python benchmark.py --task all --runs 5 --device both

File Structure

sherpa-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.json

Evaluation Results

Accuracy

  • ASR transcription matches 100% between CPU and NPU modes
  • TTS audio output matches with NRMSE < 0.0001% (effectively identical)
  • Both models maintain the original ONNX Runtime inference accuracy

Performance Characteristics

  • Real-time factor (RTF) consistently below 0.07 for both ASR and TTS
  • NPU mode provides ~5% improvement in ASR preprocessing throughput
  • Both CPU and NPU modes achieve 15-20x real-time processing speed

License

Apache License 2.0

Citation

  • SenseVoice: FunAudioLLM/SenseVoice
  • Matcha-TTS: shivammehta25/Matcha-TTS
  • sherpa-onnx: k2-fsa/sherpa-onnx