Spaces:
Sleeping
Sleeping
update
Browse files- examples/wenet/toolbox_infer.py +22 -22
- toolbox/k2_sherpa/models.py +2 -3
examples/wenet/toolbox_infer.py
CHANGED
@@ -57,31 +57,31 @@ 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 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
# decoding_method="greedy_search",
|
68 |
-
# num_active_paths=2,
|
69 |
-
# )
|
70 |
-
|
71 |
-
feat_config = sherpa.FeatureConfig(normalize_samples=False)
|
72 |
-
feat_config.fbank_opts.frame_opts.samp_freq = args.sample_rate
|
73 |
-
feat_config.fbank_opts.mel_opts.num_bins = 80
|
74 |
-
feat_config.fbank_opts.frame_opts.dither = 0
|
75 |
-
|
76 |
-
config = sherpa.OfflineRecognizerConfig(
|
77 |
-
nn_model=nn_model_file.as_posix(),
|
78 |
-
tokens=tokens_file.as_posix(),
|
79 |
-
use_gpu=False,
|
80 |
-
feat_config=feat_config,
|
81 |
decoding_method="greedy_search",
|
82 |
num_active_paths=2,
|
83 |
)
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
text = decode.decode_by_recognizer(recognizer=recognizer,
|
87 |
filename=out_filename.as_posix(),
|
|
|
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 = models.load_recognizer(
|
61 |
+
repo_id=m_dict["repo_id"],
|
62 |
+
nn_model_file=nn_model_file.as_posix(),
|
63 |
+
tokens_file=tokens_file.as_posix(),
|
64 |
+
sub_folder=m_dict["sub_folder"],
|
65 |
+
local_model_dir=local_model_dir,
|
66 |
+
recognizer_type=m_dict["recognizer_type"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
decoding_method="greedy_search",
|
68 |
num_active_paths=2,
|
69 |
)
|
70 |
+
|
71 |
+
# feat_config = sherpa.FeatureConfig(normalize_samples=False)
|
72 |
+
# feat_config.fbank_opts.frame_opts.samp_freq = args.sample_rate
|
73 |
+
# feat_config.fbank_opts.mel_opts.num_bins = 80
|
74 |
+
# feat_config.fbank_opts.frame_opts.dither = 0
|
75 |
+
#
|
76 |
+
# config = sherpa.OfflineRecognizerConfig(
|
77 |
+
# nn_model=nn_model_file.as_posix(),
|
78 |
+
# tokens=tokens_file.as_posix(),
|
79 |
+
# use_gpu=False,
|
80 |
+
# feat_config=feat_config,
|
81 |
+
# decoding_method="greedy_search",
|
82 |
+
# num_active_paths=2,
|
83 |
+
# )
|
84 |
+
# recognizer = sherpa.OfflineRecognizer(config)
|
85 |
|
86 |
text = decode.decode_by_recognizer(recognizer=recognizer,
|
87 |
filename=out_filename.as_posix(),
|
toolbox/k2_sherpa/models.py
CHANGED
@@ -56,12 +56,11 @@ def download_model(repo_id: str,
|
|
56 |
return nn_model_file, tokens_file
|
57 |
|
58 |
|
59 |
-
@lru_cache(maxsize=10)
|
60 |
def load_sherpa_offline_recognizer(nn_model_file: str,
|
61 |
tokens_file: str,
|
62 |
sample_rate: int = 16000,
|
63 |
num_active_paths: int = 2,
|
64 |
-
decoding_method:
|
65 |
num_mel_bins: int = 80,
|
66 |
frame_dither: int = 0,
|
67 |
):
|
@@ -90,7 +89,7 @@ def load_recognizer(repo_id: str,
|
|
90 |
sub_folder: str,
|
91 |
local_model_dir: str,
|
92 |
recognizer_type: str,
|
93 |
-
decoding_method:
|
94 |
num_active_paths: int = 4,
|
95 |
):
|
96 |
if not os.path.exists(local_model_dir):
|
|
|
56 |
return nn_model_file, tokens_file
|
57 |
|
58 |
|
|
|
59 |
def load_sherpa_offline_recognizer(nn_model_file: str,
|
60 |
tokens_file: str,
|
61 |
sample_rate: int = 16000,
|
62 |
num_active_paths: int = 2,
|
63 |
+
decoding_method: str = "greedy_search",
|
64 |
num_mel_bins: int = 80,
|
65 |
frame_dither: int = 0,
|
66 |
):
|
|
|
89 |
sub_folder: str,
|
90 |
local_model_dir: str,
|
91 |
recognizer_type: str,
|
92 |
+
decoding_method: str = "greedy_search",
|
93 |
num_active_paths: int = 4,
|
94 |
):
|
95 |
if not os.path.exists(local_model_dir):
|