add python tests (#111)
This commit is contained in:
@@ -18,20 +18,25 @@ def _assert_file_exists(f: str):
|
||||
|
||||
|
||||
class OfflineRecognizer(object):
|
||||
"""A class for offline speech recognition."""
|
||||
"""A class for offline speech recognition.
|
||||
|
||||
Please refer to the following files for usages
|
||||
- https://github.com/k2-fsa/sherpa-onnx/blob/master/sherpa-onnx/python/tests/test_offline_recognizer.py
|
||||
- https://github.com/k2-fsa/sherpa-onnx/blob/master/python-api-examples/offline-decode-files.py
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def from_transducer(
|
||||
cls,
|
||||
encoder: str,
|
||||
decoder: str,
|
||||
joiner: str,
|
||||
tokens: str,
|
||||
num_threads: int,
|
||||
sample_rate: int = 16000,
|
||||
feature_dim: int = 80,
|
||||
decoding_method: str = "greedy_search",
|
||||
debug: bool = False,
|
||||
cls,
|
||||
encoder: str,
|
||||
decoder: str,
|
||||
joiner: str,
|
||||
tokens: str,
|
||||
num_threads: int,
|
||||
sample_rate: int = 16000,
|
||||
feature_dim: int = 80,
|
||||
decoding_method: str = "greedy_search",
|
||||
debug: bool = False,
|
||||
):
|
||||
"""
|
||||
Please refer to
|
||||
@@ -59,7 +64,7 @@ class OfflineRecognizer(object):
|
||||
feature_dim:
|
||||
Dimension of the feature used to train the model.
|
||||
decoding_method:
|
||||
Valid values are greedy_search, modified_beam_search.
|
||||
Support only greedy_search for now.
|
||||
debug:
|
||||
True to show debug messages.
|
||||
"""
|
||||
@@ -68,14 +73,12 @@ class OfflineRecognizer(object):
|
||||
transducer=OfflineTransducerModelConfig(
|
||||
encoder_filename=encoder,
|
||||
decoder_filename=decoder,
|
||||
joiner_filename=joiner
|
||||
),
|
||||
paraformer=OfflineParaformerModelConfig(
|
||||
model=""
|
||||
joiner_filename=joiner,
|
||||
),
|
||||
paraformer=OfflineParaformerModelConfig(model=""),
|
||||
tokens=tokens,
|
||||
num_threads=num_threads,
|
||||
debug=debug
|
||||
debug=debug,
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
@@ -93,14 +96,14 @@ class OfflineRecognizer(object):
|
||||
|
||||
@classmethod
|
||||
def from_paraformer(
|
||||
cls,
|
||||
paraformer: str,
|
||||
tokens: str,
|
||||
num_threads: int,
|
||||
sample_rate: int = 16000,
|
||||
feature_dim: int = 80,
|
||||
decoding_method: str = "greedy_search",
|
||||
debug: bool = False,
|
||||
cls,
|
||||
paraformer: str,
|
||||
tokens: str,
|
||||
num_threads: int,
|
||||
sample_rate: int = 16000,
|
||||
feature_dim: int = 80,
|
||||
decoding_method: str = "greedy_search",
|
||||
debug: bool = False,
|
||||
):
|
||||
"""
|
||||
Please refer to
|
||||
@@ -131,16 +134,12 @@ class OfflineRecognizer(object):
|
||||
self = cls.__new__(cls)
|
||||
model_config = OfflineModelConfig(
|
||||
transducer=OfflineTransducerModelConfig(
|
||||
encoder_filename="",
|
||||
decoder_filename="",
|
||||
joiner_filename=""
|
||||
),
|
||||
paraformer=OfflineParaformerModelConfig(
|
||||
model=paraformer
|
||||
encoder_filename="", decoder_filename="", joiner_filename=""
|
||||
),
|
||||
paraformer=OfflineParaformerModelConfig(model=paraformer),
|
||||
tokens=tokens,
|
||||
num_threads=num_threads,
|
||||
debug=debug
|
||||
debug=debug,
|
||||
)
|
||||
|
||||
feat_config = OfflineFeatureExtractorConfig(
|
||||
@@ -164,4 +163,3 @@ class OfflineRecognizer(object):
|
||||
|
||||
def decode_streams(self, ss: List[OfflineStream]):
|
||||
self.recognizer.decode_streams(ss)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user