feat: 添加 Sherpa-ONNX Paraformer 模型支持

- 在 sherpa_onnx_local.py 中添加 model_type 参数,支持 paraformer 和 sense_voice 两种模型类型
- 在 config.yaml 中添加 SherpaParaformerASR 配置示例
- 添加详细的 Paraformer 使用文档 (docs/sherpa-paraformer-guide.md)
- 保持向后兼容,默认使用 sense_voice 模型

这个改动允许用户在低性能设备(如 RK3566)上使用更轻量的 Paraformer 模型,
相比 SenseVoice (894MB),Paraformer-small (78MB) 可以提供 4-6 倍的识别速度提升。
This commit is contained in:
yaotutu
2025-07-30 10:41:27 +08:00
parent 67c4622ca7
commit 9edd083411
3 changed files with 300 additions and 10 deletions
@@ -40,6 +40,7 @@ class ASRProvider(ASRProviderBase):
self.interface_type = InterfaceType.LOCAL
self.model_dir = config.get("model_dir")
self.output_dir = config.get("output_dir")
self.model_type = config.get("model_type", "sense_voice") # 支持 paraformer
self.delete_audio_file = delete_audio_file
# 确保输出目录存在
@@ -73,16 +74,27 @@ class ASRProvider(ASRProviderBase):
raise
with CaptureOutput():
self.model = sherpa_onnx.OfflineRecognizer.from_sense_voice(
model=self.model_path,
tokens=self.tokens_path,
num_threads=2,
sample_rate=16000,
feature_dim=80,
decoding_method="greedy_search",
debug=False,
use_itn=True,
)
if self.model_type == "paraformer":
self.model = sherpa_onnx.OfflineRecognizer.from_paraformer(
paraformer=self.model_path,
tokens=self.tokens_path,
num_threads=2,
sample_rate=16000,
feature_dim=80,
decoding_method="greedy_search",
debug=False,
)
else: # sense_voice
self.model = sherpa_onnx.OfflineRecognizer.from_sense_voice(
model=self.model_path,
tokens=self.tokens_path,
num_threads=2,
sample_rate=16000,
feature_dim=80,
decoding_method="greedy_search",
debug=False,
use_itn=True,
)
def read_wave(self, wave_filename: str) -> Tuple[np.ndarray, int]:
"""