csukuangfj
commited on
Commit
•
44ee875
1
Parent(s):
8556603
add telespeech
Browse files- model.py +32 -0
- requirements.txt +2 -1
model.py
CHANGED
@@ -123,6 +123,31 @@ def _get_paraformer_zh_pre_trained_model(repo_id: str) -> sherpa_onnx.OfflineRec
|
|
123 |
return recognizer
|
124 |
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
@lru_cache(maxsize=10)
|
127 |
def _get_russian_pre_trained_model(repo_id: str) -> sherpa_onnx.OfflineRecognizer:
|
128 |
assert repo_id in (
|
@@ -209,6 +234,8 @@ def get_vad() -> sherpa_onnx.VoiceActivityDetector:
|
|
209 |
def get_pretrained_model(repo_id: str) -> sherpa_onnx.OfflineRecognizer:
|
210 |
if repo_id in chinese_models:
|
211 |
return chinese_models[repo_id](repo_id)
|
|
|
|
|
212 |
elif repo_id in english_models:
|
213 |
return english_models[repo_id](repo_id)
|
214 |
elif repo_id in chinese_english_mixed_models:
|
@@ -335,6 +362,10 @@ def _get_english_model(repo_id: str) -> sherpa_onnx.OfflineRecognizer:
|
|
335 |
return recognizer
|
336 |
|
337 |
|
|
|
|
|
|
|
|
|
338 |
chinese_models = {
|
339 |
"csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28": _get_paraformer_zh_pre_trained_model,
|
340 |
"csukuangfj/sherpa-onnx-conformer-zh-stateless2-2023-05-23": _get_wenetspeech_pre_trained_model, # noqa
|
@@ -361,6 +392,7 @@ russian_models = {
|
|
361 |
}
|
362 |
|
363 |
language_to_models = {
|
|
|
364 |
"Chinese+English": list(chinese_english_mixed_models.keys()),
|
365 |
"Chinese": list(chinese_models.keys()),
|
366 |
"English": list(english_models.keys()),
|
|
|
123 |
return recognizer
|
124 |
|
125 |
|
126 |
+
@lru_cache(maxsize=5)
|
127 |
+
def _get_chinese_dialect_models(
|
128 |
+
repo_id: str, decoding_method: str, num_active_paths: int
|
129 |
+
) -> sherpa_onnx.OfflineRecognizer:
|
130 |
+
assert repo_id in [
|
131 |
+
"csukuangfj/sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04",
|
132 |
+
], repo_id
|
133 |
+
|
134 |
+
nn_model = _get_nn_model_filename(
|
135 |
+
repo_id=repo_id,
|
136 |
+
filename="model.int8.onnx",
|
137 |
+
subfolder=".",
|
138 |
+
)
|
139 |
+
|
140 |
+
tokens = _get_token_filename(repo_id=repo_id, subfolder=".")
|
141 |
+
|
142 |
+
recognizer = sherpa_onnx.OfflineRecognizer.from_telespeech_ctc(
|
143 |
+
model=nn_model,
|
144 |
+
tokens=tokens,
|
145 |
+
num_threads=2,
|
146 |
+
)
|
147 |
+
|
148 |
+
return recognizer
|
149 |
+
|
150 |
+
|
151 |
@lru_cache(maxsize=10)
|
152 |
def _get_russian_pre_trained_model(repo_id: str) -> sherpa_onnx.OfflineRecognizer:
|
153 |
assert repo_id in (
|
|
|
234 |
def get_pretrained_model(repo_id: str) -> sherpa_onnx.OfflineRecognizer:
|
235 |
if repo_id in chinese_models:
|
236 |
return chinese_models[repo_id](repo_id)
|
237 |
+
elif repo_id in chinese_dialect_models:
|
238 |
+
return chinese_dialect_models[repo_id](repo_id)
|
239 |
elif repo_id in english_models:
|
240 |
return english_models[repo_id](repo_id)
|
241 |
elif repo_id in chinese_english_mixed_models:
|
|
|
362 |
return recognizer
|
363 |
|
364 |
|
365 |
+
chinese_dialect_models = {
|
366 |
+
"csukuangfj/sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04": _get_chinese_dialect_models,
|
367 |
+
}
|
368 |
+
|
369 |
chinese_models = {
|
370 |
"csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28": _get_paraformer_zh_pre_trained_model,
|
371 |
"csukuangfj/sherpa-onnx-conformer-zh-stateless2-2023-05-23": _get_wenetspeech_pre_trained_model, # noqa
|
|
|
392 |
}
|
393 |
|
394 |
language_to_models = {
|
395 |
+
"超多种中文方言": list(chinese_dialect_models.keys()),
|
396 |
"Chinese+English": list(chinese_english_mixed_models.keys()),
|
397 |
"Chinese": list(chinese_models.keys()),
|
398 |
"English": list(english_models.keys()),
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
|
2 |
-
sherpa-onnx>=1.9.21
|
3 |
ffmpeg-python
|
|
|
|
1 |
|
2 |
+
# sherpa-onnx>=1.9.21
|
3 |
ffmpeg-python
|
4 |
+
https://huggingface.co/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-1.9.26-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
|