Merge pull request #1953 from yaotutu/feature/sherpa-paraformer-support

feat: 添加 Sherpa-ONNX Paraformer 模型支持
This commit is contained in:
hrz
2025-07-31 13:35:03 +08:00
committed by GitHub
2 changed files with 32 additions and 10 deletions
+10
View File
@@ -271,9 +271,19 @@ ASR:
api_key: none
output_dir: tmp/
SherpaASR:
# Sherpa-ONNX 本地语音识别(需手动下载模型)
type: sherpa_onnx_local
model_dir: models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17
output_dir: tmp/
# 模型类型:sense_voice (多语言) 或 paraformer (中文专用)
model_type: sense_voice
SherpaParaformerASR:
# 中文语音识别模型,可以运行在低性能设备(需手动下载模型,例如RK3566-2g)
# 详细配置说明请参考:docs/sherpa-paraformer-guide.md
type: sherpa_onnx_local
model_dir: models/sherpa-onnx-paraformer-zh-small-2024-03-09
output_dir: tmp/
model_type: paraformer
DoubaoASR:
# 可以在这里申请相关Key等信息
# https://console.volcengine.com/speech/app
@@ -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]:
"""