Commit
·
f396d7e
1
Parent(s):
4bf1ac3
add vietnamese asr
Browse files
model.py
CHANGED
|
@@ -228,6 +228,10 @@ def get_pretrained_model(
|
|
| 228 |
return thai_models[repo_id](
|
| 229 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 230 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
else:
|
| 232 |
raise ValueError(f"Unsupported repo_id: {repo_id}")
|
| 233 |
|
|
@@ -352,6 +356,64 @@ def _get_offline_pre_trained_model(
|
|
| 352 |
return recognizer
|
| 353 |
|
| 354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
@lru_cache(maxsize=10)
|
| 356 |
def _get_yifan_thai_pretrained_model(
|
| 357 |
repo_id: str, decoding_method: str, num_active_paths: int
|
|
@@ -1899,6 +1961,11 @@ thai_models = {
|
|
| 1899 |
"yfyeung/icefall-asr-gigaspeech2-th-zipformer-2024-06-20": _get_yifan_thai_pretrained_model,
|
| 1900 |
}
|
| 1901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1902 |
|
| 1903 |
all_models = {
|
| 1904 |
**multi_lingual_models,
|
|
@@ -1916,6 +1983,7 @@ all_models = {
|
|
| 1916 |
**russian_models,
|
| 1917 |
**korean_models,
|
| 1918 |
**thai_models,
|
|
|
|
| 1919 |
}
|
| 1920 |
|
| 1921 |
language_to_models = {
|
|
@@ -1937,4 +2005,5 @@ language_to_models = {
|
|
| 1937 |
"Russian": list(russian_models.keys()),
|
| 1938 |
"Korean": list(korean_models.keys()),
|
| 1939 |
"Thai": list(thai_models.keys()),
|
|
|
|
| 1940 |
}
|
|
|
|
| 228 |
return thai_models[repo_id](
|
| 229 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 230 |
)
|
| 231 |
+
elif repo_id in vietnamese_models:
|
| 232 |
+
return vietnamese_models[repo_id](
|
| 233 |
+
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 234 |
+
)
|
| 235 |
else:
|
| 236 |
raise ValueError(f"Unsupported repo_id: {repo_id}")
|
| 237 |
|
|
|
|
| 356 |
return recognizer
|
| 357 |
|
| 358 |
|
| 359 |
+
@lru_cache(maxsize=10)
|
| 360 |
+
def _get_vietnamese_pretrained_model(
|
| 361 |
+
repo_id: str, decoding_method: str, num_active_paths: int
|
| 362 |
+
) -> sherpa_onnx.OfflineRecognizer:
|
| 363 |
+
assert repo_id in (
|
| 364 |
+
"csukuangfj/sherpa-onnx-zipformer-vi-int8-2025-04-20",
|
| 365 |
+
"csukuangfj/sherpa-onnx-zipformer-vi-2025-04-20",
|
| 366 |
+
), repo_id
|
| 367 |
+
|
| 368 |
+
decoder_model = _get_nn_model_filename(
|
| 369 |
+
repo_id=repo_id,
|
| 370 |
+
filename="decoder-epoch-12-avg-8.onnx",
|
| 371 |
+
subfolder=".",
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
if repo_id == "csukuangfj/sherpa-onnx-zipformer-vi-int8-2025-04-20":
|
| 375 |
+
encoder_model = _get_nn_model_filename(
|
| 376 |
+
repo_id=repo_id,
|
| 377 |
+
filename="encoder-epoch-12-avg-8.int8.onnx",
|
| 378 |
+
subfolder=".",
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
joiner_model = _get_nn_model_filename(
|
| 382 |
+
repo_id=repo_id,
|
| 383 |
+
filename="joiner-epoch-12-avg-8.int8.onnx",
|
| 384 |
+
subfolder=".",
|
| 385 |
+
)
|
| 386 |
+
elif repo_id == "csukuangfj/sherpa-onnx-zipformer-vi-2025-04-20":
|
| 387 |
+
encoder_model = _get_nn_model_filename(
|
| 388 |
+
repo_id=repo_id,
|
| 389 |
+
filename="encoder-epoch-12-avg-8.onnx",
|
| 390 |
+
subfolder=".",
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
joiner_model = _get_nn_model_filename(
|
| 394 |
+
repo_id=repo_id,
|
| 395 |
+
filename="joiner-epoch-12-avg-8.onnx",
|
| 396 |
+
subfolder=".",
|
| 397 |
+
)
|
| 398 |
+
else:
|
| 399 |
+
raise ValueError(f"repo_id: {repo_id}")
|
| 400 |
+
|
| 401 |
+
tokens = _get_token_filename(repo_id=repo_id, subfolder=".")
|
| 402 |
+
|
| 403 |
+
recognizer = sherpa_onnx.OfflineRecognizer.from_transducer(
|
| 404 |
+
tokens=tokens,
|
| 405 |
+
encoder=encoder_model,
|
| 406 |
+
decoder=decoder_model,
|
| 407 |
+
joiner=joiner_model,
|
| 408 |
+
num_threads=2,
|
| 409 |
+
sample_rate=16000,
|
| 410 |
+
feature_dim=80,
|
| 411 |
+
decoding_method=decoding_method,
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
return recognizer
|
| 415 |
+
|
| 416 |
+
|
| 417 |
@lru_cache(maxsize=10)
|
| 418 |
def _get_yifan_thai_pretrained_model(
|
| 419 |
repo_id: str, decoding_method: str, num_active_paths: int
|
|
|
|
| 1961 |
"yfyeung/icefall-asr-gigaspeech2-th-zipformer-2024-06-20": _get_yifan_thai_pretrained_model,
|
| 1962 |
}
|
| 1963 |
|
| 1964 |
+
vietnamese_models = {
|
| 1965 |
+
"csukuangfj/sherpa-onnx-zipformer-vi-int8-2025-04-20": _get_vietnamese_pretrained_model,
|
| 1966 |
+
"csukuangfj/sherpa-onnx-zipformer-vi-2025-04-20": _get_vietnamese_pretrained_model,
|
| 1967 |
+
}
|
| 1968 |
+
|
| 1969 |
|
| 1970 |
all_models = {
|
| 1971 |
**multi_lingual_models,
|
|
|
|
| 1983 |
**russian_models,
|
| 1984 |
**korean_models,
|
| 1985 |
**thai_models,
|
| 1986 |
+
**vietnamese_models,
|
| 1987 |
}
|
| 1988 |
|
| 1989 |
language_to_models = {
|
|
|
|
| 2005 |
"Russian": list(russian_models.keys()),
|
| 2006 |
"Korean": list(korean_models.keys()),
|
| 2007 |
"Thai": list(thai_models.keys()),
|
| 2008 |
+
"Vietnamese": list(vietnamese_models.keys()),
|
| 2009 |
}
|