Support CoreML for macOS (#151)

This commit is contained in:
Fangjun Kuang
2023-05-12 15:57:44 +08:00
committed by GitHub
parent de1880948b
commit cea718e3d8
22 changed files with 216 additions and 87 deletions

View File

@@ -24,17 +24,19 @@ void PybindOfflineModelConfig(py::module *m) {
.def(py::init<const OfflineTransducerModelConfig &,
const OfflineParaformerModelConfig &,
const OfflineNemoEncDecCtcModelConfig &,
const std::string &, int32_t, bool>(),
const std::string &, int32_t, bool, const std::string &>(),
py::arg("transducer") = OfflineTransducerModelConfig(),
py::arg("paraformer") = OfflineParaformerModelConfig(),
py::arg("nemo_ctc") = OfflineNemoEncDecCtcModelConfig(),
py::arg("tokens"), py::arg("num_threads"), py::arg("debug") = false)
py::arg("tokens"), py::arg("num_threads"), py::arg("debug") = false,
py::arg("provider") = "cpu")
.def_readwrite("transducer", &PyClass::transducer)
.def_readwrite("paraformer", &PyClass::paraformer)
.def_readwrite("nemo_ctc", &PyClass::nemo_ctc)
.def_readwrite("tokens", &PyClass::tokens)
.def_readwrite("num_threads", &PyClass::num_threads)
.def_readwrite("debug", &PyClass::debug)
.def_readwrite("provider", &PyClass::provider)
.def("__str__", &PyClass::ToString);
}

View File

@@ -14,16 +14,19 @@ void PybindOnlineTransducerModelConfig(py::module *m) {
using PyClass = OnlineTransducerModelConfig;
py::class_<PyClass>(*m, "OnlineTransducerModelConfig")
.def(py::init<const std::string &, const std::string &,
const std::string &, const std::string &, int32_t, bool>(),
const std::string &, const std::string &, int32_t, bool,
const std::string &>(),
py::arg("encoder_filename"), py::arg("decoder_filename"),
py::arg("joiner_filename"), py::arg("tokens"),
py::arg("num_threads"), py::arg("debug") = false)
py::arg("num_threads"), py::arg("debug") = false,
py::arg("provider") = "cpu")
.def_readwrite("encoder_filename", &PyClass::encoder_filename)
.def_readwrite("decoder_filename", &PyClass::decoder_filename)
.def_readwrite("joiner_filename", &PyClass::joiner_filename)
.def_readwrite("tokens", &PyClass::tokens)
.def_readwrite("num_threads", &PyClass::num_threads)
.def_readwrite("debug", &PyClass::debug)
.def_readwrite("provider", &PyClass::provider)
.def("__str__", &PyClass::ToString);
}

View File

@@ -40,6 +40,7 @@ class OfflineRecognizer(object):
feature_dim: int = 80,
decoding_method: str = "greedy_search",
debug: bool = False,
provider: str = "cpu",
):
"""
Please refer to
@@ -70,6 +71,8 @@ class OfflineRecognizer(object):
Support only greedy_search for now.
debug:
True to show debug messages.
provider:
onnxruntime execution providers. Valid values are: cpu, cuda, coreml.
"""
self = cls.__new__(cls)
model_config = OfflineModelConfig(
@@ -81,6 +84,7 @@ class OfflineRecognizer(object):
tokens=tokens,
num_threads=num_threads,
debug=debug,
provider=provider,
)
feat_config = OfflineFeatureExtractorConfig(

View File

@@ -39,6 +39,7 @@ class OnlineRecognizer(object):
rule3_min_utterance_length: float = 20.0,
decoding_method: str = "greedy_search",
max_active_paths: int = 4,
provider: str = "cpu",
):
"""
Please refer to
@@ -86,6 +87,8 @@ class OnlineRecognizer(object):
max_active_paths:
Use only when decoding_method is modified_beam_search. It specifies
the maximum number of active paths during beam search.
provider:
onnxruntime execution providers. Valid values are: cpu, cuda, coreml.
"""
_assert_file_exists(tokens)
_assert_file_exists(encoder)
@@ -100,6 +103,7 @@ class OnlineRecognizer(object):
joiner_filename=joiner,
tokens=tokens,
num_threads=num_threads,
provider=provider,
)
feat_config = FeatureExtractorConfig(