Refactor hotwords,support loading hotwords from file (#296)
This commit is contained in:
@@ -16,17 +16,19 @@ static void PybindOfflineRecognizerConfig(py::module *m) {
|
||||
py::class_<PyClass>(*m, "OfflineRecognizerConfig")
|
||||
.def(py::init<const OfflineFeatureExtractorConfig &,
|
||||
const OfflineModelConfig &, const OfflineLMConfig &,
|
||||
const std::string &, int32_t, float>(),
|
||||
const std::string &, int32_t, const std::string &, float>(),
|
||||
py::arg("feat_config"), py::arg("model_config"),
|
||||
py::arg("lm_config") = OfflineLMConfig(),
|
||||
py::arg("decoding_method") = "greedy_search",
|
||||
py::arg("max_active_paths") = 4, py::arg("context_score") = 1.5)
|
||||
py::arg("max_active_paths") = 4, py::arg("hotwords_file") = "",
|
||||
py::arg("hotwords_score") = 1.5)
|
||||
.def_readwrite("feat_config", &PyClass::feat_config)
|
||||
.def_readwrite("model_config", &PyClass::model_config)
|
||||
.def_readwrite("lm_config", &PyClass::lm_config)
|
||||
.def_readwrite("decoding_method", &PyClass::decoding_method)
|
||||
.def_readwrite("max_active_paths", &PyClass::max_active_paths)
|
||||
.def_readwrite("context_score", &PyClass::context_score)
|
||||
.def_readwrite("hotwords_file", &PyClass::hotwords_file)
|
||||
.def_readwrite("hotwords_score", &PyClass::hotwords_score)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
@@ -40,11 +42,10 @@ void PybindOfflineRecognizer(py::module *m) {
|
||||
[](const PyClass &self) { return self.CreateStream(); })
|
||||
.def(
|
||||
"create_stream",
|
||||
[](PyClass &self,
|
||||
const std::vector<std::vector<int32_t>> &contexts_list) {
|
||||
return self.CreateStream(contexts_list);
|
||||
[](PyClass &self, const std::string &hotwords) {
|
||||
return self.CreateStream(hotwords);
|
||||
},
|
||||
py::arg("contexts_list"))
|
||||
py::arg("hotwords"))
|
||||
.def("decode_stream", &PyClass::DecodeStream)
|
||||
.def("decode_streams",
|
||||
[](const PyClass &self, std::vector<OfflineStream *> ss) {
|
||||
|
||||
@@ -21,8 +21,8 @@ void PybindOnlineModelConfig(py::module *m) {
|
||||
using PyClass = OnlineModelConfig;
|
||||
py::class_<PyClass>(*m, "OnlineModelConfig")
|
||||
.def(py::init<const OnlineTransducerModelConfig &,
|
||||
const OnlineParaformerModelConfig &, std::string &, int32_t,
|
||||
bool, const std::string &, const std::string &>(),
|
||||
const OnlineParaformerModelConfig &, const std::string &,
|
||||
int32_t, bool, const std::string &, const std::string &>(),
|
||||
py::arg("transducer") = OnlineTransducerModelConfig(),
|
||||
py::arg("paraformer") = OnlineParaformerModelConfig(),
|
||||
py::arg("tokens"), py::arg("num_threads"), py::arg("debug") = false,
|
||||
|
||||
@@ -29,18 +29,20 @@ static void PybindOnlineRecognizerConfig(py::module *m) {
|
||||
py::class_<PyClass>(*m, "OnlineRecognizerConfig")
|
||||
.def(py::init<const FeatureExtractorConfig &, const OnlineModelConfig &,
|
||||
const OnlineLMConfig &, const EndpointConfig &, bool,
|
||||
const std::string &, int32_t, float>(),
|
||||
const std::string &, int32_t, const std::string &, float>(),
|
||||
py::arg("feat_config"), py::arg("model_config"),
|
||||
py::arg("lm_config") = OnlineLMConfig(), py::arg("endpoint_config"),
|
||||
py::arg("enable_endpoint"), py::arg("decoding_method"),
|
||||
py::arg("max_active_paths") = 4, py::arg("context_score") = 0)
|
||||
py::arg("max_active_paths") = 4, py::arg("hotwords_file") = "",
|
||||
py::arg("hotwords_score") = 0)
|
||||
.def_readwrite("feat_config", &PyClass::feat_config)
|
||||
.def_readwrite("model_config", &PyClass::model_config)
|
||||
.def_readwrite("endpoint_config", &PyClass::endpoint_config)
|
||||
.def_readwrite("enable_endpoint", &PyClass::enable_endpoint)
|
||||
.def_readwrite("decoding_method", &PyClass::decoding_method)
|
||||
.def_readwrite("max_active_paths", &PyClass::max_active_paths)
|
||||
.def_readwrite("context_score", &PyClass::context_score)
|
||||
.def_readwrite("hotwords_file", &PyClass::hotwords_file)
|
||||
.def_readwrite("hotwords_score", &PyClass::hotwords_score)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
@@ -55,11 +57,10 @@ void PybindOnlineRecognizer(py::module *m) {
|
||||
[](const PyClass &self) { return self.CreateStream(); })
|
||||
.def(
|
||||
"create_stream",
|
||||
[](PyClass &self,
|
||||
const std::vector<std::vector<int32_t>> &contexts_list) {
|
||||
return self.CreateStream(contexts_list);
|
||||
[](PyClass &self, const std::string &hotwords) {
|
||||
return self.CreateStream(hotwords);
|
||||
},
|
||||
py::arg("contexts_list"))
|
||||
py::arg("hotwords"))
|
||||
.def("is_ready", &PyClass::IsReady)
|
||||
.def("decode_stream", &PyClass::DecodeStream)
|
||||
.def("decode_streams",
|
||||
|
||||
Reference in New Issue
Block a user