Spaces:
Sleeping
Sleeping
update
Browse files
examples/wenet/toolbox_infer.py
CHANGED
|
@@ -38,6 +38,31 @@ def get_args():
|
|
| 38 |
return args
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def main():
|
| 42 |
args = get_args()
|
| 43 |
|
|
@@ -57,7 +82,7 @@ def main():
|
|
| 57 |
nn_model_file = local_model_dir / m_dict["nn_model_file"]
|
| 58 |
tokens_file = local_model_dir / m_dict["tokens_file"]
|
| 59 |
|
| 60 |
-
recognizer =
|
| 61 |
nn_model_file=nn_model_file.as_posix(),
|
| 62 |
tokens_file=tokens_file.as_posix(),
|
| 63 |
decoding_method="greedy_search",
|
|
|
|
| 38 |
return args
|
| 39 |
|
| 40 |
|
| 41 |
+
def load_sherpa_offline_recognizer(nn_model_file: str,
|
| 42 |
+
tokens_file: str,
|
| 43 |
+
sample_rate: int = 16000,
|
| 44 |
+
num_active_paths: int = 2,
|
| 45 |
+
decoding_method: str = "greedy_search",
|
| 46 |
+
num_mel_bins: int = 80,
|
| 47 |
+
frame_dither: int = 0,
|
| 48 |
+
):
|
| 49 |
+
feat_config = sherpa.FeatureConfig(normalize_samples=False)
|
| 50 |
+
feat_config.fbank_opts.frame_opts.samp_freq = sample_rate
|
| 51 |
+
feat_config.fbank_opts.mel_opts.num_bins = 80
|
| 52 |
+
feat_config.fbank_opts.frame_opts.dither = 0
|
| 53 |
+
|
| 54 |
+
config = sherpa.OfflineRecognizerConfig(
|
| 55 |
+
nn_model=nn_model_file,
|
| 56 |
+
tokens=tokens_file,
|
| 57 |
+
use_gpu=False,
|
| 58 |
+
feat_config=feat_config,
|
| 59 |
+
decoding_method="greedy_search",
|
| 60 |
+
num_active_paths=2,
|
| 61 |
+
)
|
| 62 |
+
recognizer = sherpa.OfflineRecognizer(config)
|
| 63 |
+
return recognizer
|
| 64 |
+
|
| 65 |
+
|
| 66 |
def main():
|
| 67 |
args = get_args()
|
| 68 |
|
|
|
|
| 82 |
nn_model_file = local_model_dir / m_dict["nn_model_file"]
|
| 83 |
tokens_file = local_model_dir / m_dict["tokens_file"]
|
| 84 |
|
| 85 |
+
recognizer = load_sherpa_offline_recognizer(
|
| 86 |
nn_model_file=nn_model_file.as_posix(),
|
| 87 |
tokens_file=tokens_file.as_posix(),
|
| 88 |
decoding_method="greedy_search",
|