Spaces:
Build error
Build error
Commit
·
6eeaa1f
1
Parent(s):
793d2e7
add a cantonese model
Browse files
model.py
CHANGED
|
@@ -172,6 +172,10 @@ def get_pretrained_model(
|
|
| 172 |
return chinese_cantonese_english_models[repo_id](
|
| 173 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 174 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
elif repo_id in tibetan_models:
|
| 176 |
return tibetan_models[repo_id](
|
| 177 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
|
@@ -277,6 +281,46 @@ def _get_aishell2_pretrained_model(
|
|
| 277 |
return recognizer
|
| 278 |
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
@lru_cache(maxsize=10)
|
| 281 |
def _get_russian_pre_trained_model(
|
| 282 |
repo_id: str, decoding_method: str, num_active_paths: int
|
|
@@ -1256,12 +1300,17 @@ chinese_cantonese_english_models = {
|
|
| 1256 |
"csukuangfj/sherpa-onnx-streaming-paraformer-trilingual-zh-cantonese-en": _get_streaming_paraformer_zh_yue_en_pre_trained_model,
|
| 1257 |
}
|
| 1258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1259 |
|
| 1260 |
all_models = {
|
| 1261 |
**chinese_models,
|
| 1262 |
**english_models,
|
| 1263 |
**chinese_english_mixed_models,
|
| 1264 |
**chinese_cantonese_english_models,
|
|
|
|
| 1265 |
# **japanese_models,
|
| 1266 |
**tibetan_models,
|
| 1267 |
**arabic_models,
|
|
@@ -1275,6 +1324,7 @@ language_to_models = {
|
|
| 1275 |
"English": list(english_models.keys()),
|
| 1276 |
"Chinese+English": list(chinese_english_mixed_models.keys()),
|
| 1277 |
"Chinese+English+Cantonese": list(chinese_cantonese_english_models.keys()),
|
|
|
|
| 1278 |
# "Japanese": list(japanese_models.keys()),
|
| 1279 |
"Tibetan": list(tibetan_models.keys()),
|
| 1280 |
"Arabic": list(arabic_models.keys()),
|
|
|
|
| 172 |
return chinese_cantonese_english_models[repo_id](
|
| 173 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 174 |
)
|
| 175 |
+
elif repo_id in cantonese_models:
|
| 176 |
+
return cantonese_models[repo_id](
|
| 177 |
+
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 178 |
+
)
|
| 179 |
elif repo_id in tibetan_models:
|
| 180 |
return tibetan_models[repo_id](
|
| 181 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
|
|
|
| 281 |
return recognizer
|
| 282 |
|
| 283 |
|
| 284 |
+
@lru_cache(maxsize=10)
|
| 285 |
+
def _get_zrjin_cantonese_pre_trained_model(
|
| 286 |
+
repo_id: str, decoding_method: str, num_active_paths: int
|
| 287 |
+
) -> sherpa_onnx.OfflineRecognizer:
|
| 288 |
+
assert repo_id in ("zrjin/icefall-asr-mdcc-zipformer-2024-03-11",), repo_id
|
| 289 |
+
|
| 290 |
+
encoder_model = _get_nn_model_filename(
|
| 291 |
+
repo_id=repo_id,
|
| 292 |
+
filename="encoder-epoch-45-avg-35.int8.onnx",
|
| 293 |
+
subfolder="exp",
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
decoder_model = _get_nn_model_filename(
|
| 297 |
+
repo_id=repo_id,
|
| 298 |
+
filename="decoder-epoch-45-avg-35.onnx",
|
| 299 |
+
subfolder="exp",
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
joiner_model = _get_nn_model_filename(
|
| 303 |
+
repo_id=repo_id,
|
| 304 |
+
filename="joiner-epoch-45-avg-35.int8.onnx",
|
| 305 |
+
subfolder="exp",
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
tokens = _get_token_filename(repo_id=repo_id, subfolder="data/lang_char")
|
| 309 |
+
|
| 310 |
+
recognizer = sherpa_onnx.OfflineRecognizer.from_transducer(
|
| 311 |
+
tokens=tokens,
|
| 312 |
+
encoder=encoder_model,
|
| 313 |
+
decoder=decoder_model,
|
| 314 |
+
joiner=joiner_model,
|
| 315 |
+
num_threads=2,
|
| 316 |
+
sample_rate=16000,
|
| 317 |
+
feature_dim=80,
|
| 318 |
+
decoding_method=decoding_method,
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
return recognizer
|
| 322 |
+
|
| 323 |
+
|
| 324 |
@lru_cache(maxsize=10)
|
| 325 |
def _get_russian_pre_trained_model(
|
| 326 |
repo_id: str, decoding_method: str, num_active_paths: int
|
|
|
|
| 1300 |
"csukuangfj/sherpa-onnx-streaming-paraformer-trilingual-zh-cantonese-en": _get_streaming_paraformer_zh_yue_en_pre_trained_model,
|
| 1301 |
}
|
| 1302 |
|
| 1303 |
+
cantonese_models = {
|
| 1304 |
+
"zrjin/icefall-asr-mdcc-zipformer-2024-03-11": _get_zrjin_cantonese_pre_trained_model,
|
| 1305 |
+
}
|
| 1306 |
+
|
| 1307 |
|
| 1308 |
all_models = {
|
| 1309 |
**chinese_models,
|
| 1310 |
**english_models,
|
| 1311 |
**chinese_english_mixed_models,
|
| 1312 |
**chinese_cantonese_english_models,
|
| 1313 |
+
**cantonese_models,
|
| 1314 |
# **japanese_models,
|
| 1315 |
**tibetan_models,
|
| 1316 |
**arabic_models,
|
|
|
|
| 1324 |
"English": list(english_models.keys()),
|
| 1325 |
"Chinese+English": list(chinese_english_mixed_models.keys()),
|
| 1326 |
"Chinese+English+Cantonese": list(chinese_cantonese_english_models.keys()),
|
| 1327 |
+
"Cantonese": list(cantonese_models.keys()),
|
| 1328 |
# "Japanese": list(japanese_models.keys()),
|
| 1329 |
"Tibetan": list(tibetan_models.keys()),
|
| 1330 |
"Arabic": list(arabic_models.keys()),
|