Spaces:
Build error
Build error
Commit
·
62e20af
1
Parent(s):
7fc713f
add russian
Browse files- examples.py +3 -3
- model.py +57 -1
- test_wavs/russian/test.wav +0 -0
examples.py
CHANGED
|
@@ -38,11 +38,11 @@ examples = [
|
|
| 38 |
"./test_wavs/paraformer-zh/四川话.wav",
|
| 39 |
],
|
| 40 |
[
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
"greedy_search",
|
| 44 |
4,
|
| 45 |
-
"./test_wavs/
|
| 46 |
],
|
| 47 |
[
|
| 48 |
"German",
|
|
|
|
| 38 |
"./test_wavs/paraformer-zh/四川话.wav",
|
| 39 |
],
|
| 40 |
[
|
| 41 |
+
"Russian",
|
| 42 |
+
"alphacep/vosk-model-ru",
|
| 43 |
"greedy_search",
|
| 44 |
4,
|
| 45 |
+
"./test_wavs/russian/test.wav",
|
| 46 |
],
|
| 47 |
[
|
| 48 |
"German",
|
model.py
CHANGED
|
@@ -188,6 +188,10 @@ def get_pretrained_model(
|
|
| 188 |
return japanese_models[repo_id](
|
| 189 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 190 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
else:
|
| 192 |
raise ValueError(f"Unsupported repo_id: {repo_id}")
|
| 193 |
|
|
@@ -268,6 +272,51 @@ def _get_aishell2_pretrained_model(
|
|
| 268 |
|
| 269 |
return recognizer
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
@lru_cache(maxsize=10)
|
| 273 |
def _get_whisper_model(
|
|
@@ -768,7 +817,7 @@ def _get_french_pre_trained_model(
|
|
| 768 |
encoder=encoder_model,
|
| 769 |
decoder=decoder_model,
|
| 770 |
joiner=joiner_model,
|
| 771 |
-
num_threads=
|
| 772 |
sample_rate=16000,
|
| 773 |
feature_dim=80,
|
| 774 |
decoding_method=decoding_method,
|
|
@@ -919,6 +968,11 @@ japanese_models = {
|
|
| 919 |
"TeoWenShen/icefall-asr-csj-pruned-transducer-stateless7-streaming-230208-disfluent": _get_japanese_pre_trained_model,
|
| 920 |
}
|
| 921 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
all_models = {
|
| 923 |
**chinese_models,
|
| 924 |
**english_models,
|
|
@@ -928,6 +982,7 @@ all_models = {
|
|
| 928 |
**arabic_models,
|
| 929 |
**german_models,
|
| 930 |
**french_models,
|
|
|
|
| 931 |
}
|
| 932 |
|
| 933 |
language_to_models = {
|
|
@@ -939,4 +994,5 @@ language_to_models = {
|
|
| 939 |
"Arabic": list(arabic_models.keys()),
|
| 940 |
"German": list(german_models.keys()),
|
| 941 |
"French": list(french_models.keys()),
|
|
|
|
| 942 |
}
|
|
|
|
| 188 |
return japanese_models[repo_id](
|
| 189 |
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 190 |
)
|
| 191 |
+
elif repo_id in russian_models:
|
| 192 |
+
return russian_models[repo_id](
|
| 193 |
+
repo_id, decoding_method=decoding_method, num_active_paths=num_active_paths
|
| 194 |
+
)
|
| 195 |
else:
|
| 196 |
raise ValueError(f"Unsupported repo_id: {repo_id}")
|
| 197 |
|
|
|
|
| 272 |
|
| 273 |
return recognizer
|
| 274 |
|
| 275 |
+
@lru_cache(maxsize=10)
|
| 276 |
+
def _get_russian_pre_trained_model(
|
| 277 |
+
repo_id: str, decoding_method: str, num_active_paths: int
|
| 278 |
+
) -> sherpa_onnx.OfflineRecognizer:
|
| 279 |
+
assert repo_id in ("alphacep/vosk-model-ru", "alphacep/vosk-model-small-ru"), repo_id
|
| 280 |
+
|
| 281 |
+
if repo_id == "alphacep/vosk-model-ru":
|
| 282 |
+
model_dir = "am-onnx"
|
| 283 |
+
elif repo_id == "alphacep/vosk-model-small-ru":
|
| 284 |
+
model_dir = "am"
|
| 285 |
+
|
| 286 |
+
encoder_model = _get_nn_model_filename(
|
| 287 |
+
repo_id=repo_id,
|
| 288 |
+
filename="encoder.onnx",
|
| 289 |
+
subfolder=model_dir,
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
decoder_model = _get_nn_model_filename(
|
| 293 |
+
repo_id=repo_id,
|
| 294 |
+
filename="decoder.onnx",
|
| 295 |
+
subfolder=model_dir,
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
joiner_model = _get_nn_model_filename(
|
| 299 |
+
repo_id=repo_id,
|
| 300 |
+
filename="joiner.onnx",
|
| 301 |
+
subfolder=model_dir,
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
tokens = _get_token_filename(repo_id=repo_id, subfolder="lang")
|
| 305 |
+
|
| 306 |
+
recognizer = sherpa_onnx.OfflineRecognizer(
|
| 307 |
+
tokens=tokens,
|
| 308 |
+
encoder=encoder_model,
|
| 309 |
+
decoder=decoder_model,
|
| 310 |
+
joiner=joiner_model,
|
| 311 |
+
num_threads=2,
|
| 312 |
+
sample_rate=16000,
|
| 313 |
+
feature_dim=80,
|
| 314 |
+
decoding_method=decoding_method,
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
return recognizer
|
| 318 |
+
|
| 319 |
+
|
| 320 |
|
| 321 |
@lru_cache(maxsize=10)
|
| 322 |
def _get_whisper_model(
|
|
|
|
| 817 |
encoder=encoder_model,
|
| 818 |
decoder=decoder_model,
|
| 819 |
joiner=joiner_model,
|
| 820 |
+
num_threads=2,
|
| 821 |
sample_rate=16000,
|
| 822 |
feature_dim=80,
|
| 823 |
decoding_method=decoding_method,
|
|
|
|
| 968 |
"TeoWenShen/icefall-asr-csj-pruned-transducer-stateless7-streaming-230208-disfluent": _get_japanese_pre_trained_model,
|
| 969 |
}
|
| 970 |
|
| 971 |
+
russian_models = {
|
| 972 |
+
"alphacep/vosk-model-ru": _get_russian_pre_trained_model,
|
| 973 |
+
"alphacep/vosk-model-small-ru": _get_russian_pre_trained_model,
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
all_models = {
|
| 977 |
**chinese_models,
|
| 978 |
**english_models,
|
|
|
|
| 982 |
**arabic_models,
|
| 983 |
**german_models,
|
| 984 |
**french_models,
|
| 985 |
+
**russian_models,
|
| 986 |
}
|
| 987 |
|
| 988 |
language_to_models = {
|
|
|
|
| 994 |
"Arabic": list(arabic_models.keys()),
|
| 995 |
"German": list(german_models.keys()),
|
| 996 |
"French": list(french_models.keys()),
|
| 997 |
+
"Russian": list(russian_models.keys()),
|
| 998 |
}
|
test_wavs/russian/test.wav
ADDED
|
Binary file (227 kB). View file
|
|
|