2023-04-02 13:17:43 +08:00
|
|
|
// sherpa-onnx/python/csrc/offline-recognizer.cc
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2023 by manyeyes
|
|
|
|
|
|
|
|
|
|
#include "sherpa-onnx/python/csrc/offline-recognizer.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
|
|
|
|
|
|
|
|
|
namespace sherpa_onnx {
|
|
|
|
|
|
|
|
|
|
static void PybindOfflineRecognizerConfig(py::module *m) {
|
|
|
|
|
using PyClass = OfflineRecognizerConfig;
|
|
|
|
|
py::class_<PyClass>(*m, "OfflineRecognizerConfig")
|
|
|
|
|
.def(py::init<const OfflineFeatureExtractorConfig &,
|
2023-04-23 17:15:18 +08:00
|
|
|
const OfflineModelConfig &, const OfflineLMConfig &,
|
2023-10-08 11:32:39 +08:00
|
|
|
const OfflineCtcFstDecoderConfig &, const std::string &,
|
2024-01-25 15:00:09 +08:00
|
|
|
int32_t, const std::string &, float, float>(),
|
2023-04-02 13:17:43 +08:00
|
|
|
py::arg("feat_config"), py::arg("model_config"),
|
2023-04-23 17:15:18 +08:00
|
|
|
py::arg("lm_config") = OfflineLMConfig(),
|
2023-10-08 11:32:39 +08:00
|
|
|
py::arg("ctc_fst_decoder_config") = OfflineCtcFstDecoderConfig(),
|
2023-04-23 17:15:18 +08:00
|
|
|
py::arg("decoding_method") = "greedy_search",
|
2023-09-14 19:33:17 +08:00
|
|
|
py::arg("max_active_paths") = 4, py::arg("hotwords_file") = "",
|
2024-01-25 15:00:09 +08:00
|
|
|
py::arg("hotwords_score") = 1.5,
|
|
|
|
|
py::arg("blank_penalty") = 0.0)
|
2023-04-02 13:17:43 +08:00
|
|
|
.def_readwrite("feat_config", &PyClass::feat_config)
|
|
|
|
|
.def_readwrite("model_config", &PyClass::model_config)
|
2023-04-23 17:15:18 +08:00
|
|
|
.def_readwrite("lm_config", &PyClass::lm_config)
|
2023-10-08 11:32:39 +08:00
|
|
|
.def_readwrite("ctc_fst_decoder_config", &PyClass::ctc_fst_decoder_config)
|
2023-04-02 13:17:43 +08:00
|
|
|
.def_readwrite("decoding_method", &PyClass::decoding_method)
|
2023-04-23 17:15:18 +08:00
|
|
|
.def_readwrite("max_active_paths", &PyClass::max_active_paths)
|
2023-09-14 19:33:17 +08:00
|
|
|
.def_readwrite("hotwords_file", &PyClass::hotwords_file)
|
|
|
|
|
.def_readwrite("hotwords_score", &PyClass::hotwords_score)
|
2024-01-25 15:00:09 +08:00
|
|
|
.def_readwrite("blank_penalty", &PyClass::blank_penalty)
|
2023-04-02 13:17:43 +08:00
|
|
|
.def("__str__", &PyClass::ToString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PybindOfflineRecognizer(py::module *m) {
|
|
|
|
|
PybindOfflineRecognizerConfig(m);
|
|
|
|
|
|
|
|
|
|
using PyClass = OfflineRecognizer;
|
|
|
|
|
py::class_<PyClass>(*m, "OfflineRecognizer")
|
2023-12-20 15:54:32 +08:00
|
|
|
.def(py::init<const OfflineRecognizerConfig &>(), py::arg("config"),
|
|
|
|
|
py::call_guard<py::gil_scoped_release>())
|
2023-11-27 13:44:03 +08:00
|
|
|
.def(
|
|
|
|
|
"create_stream",
|
|
|
|
|
[](const PyClass &self) { return self.CreateStream(); },
|
|
|
|
|
py::call_guard<py::gil_scoped_release>())
|
2023-06-16 14:26:36 +08:00
|
|
|
.def(
|
|
|
|
|
"create_stream",
|
2023-09-14 19:33:17 +08:00
|
|
|
[](PyClass &self, const std::string &hotwords) {
|
|
|
|
|
return self.CreateStream(hotwords);
|
2023-06-16 14:26:36 +08:00
|
|
|
},
|
2023-11-27 13:44:03 +08:00
|
|
|
py::arg("hotwords"), py::call_guard<py::gil_scoped_release>())
|
|
|
|
|
.def("decode_stream", &PyClass::DecodeStream,
|
|
|
|
|
py::call_guard<py::gil_scoped_release>())
|
|
|
|
|
.def(
|
|
|
|
|
"decode_streams",
|
|
|
|
|
[](const PyClass &self, std::vector<OfflineStream *> ss) {
|
|
|
|
|
self.DecodeStreams(ss.data(), ss.size());
|
|
|
|
|
},
|
|
|
|
|
py::call_guard<py::gil_scoped_release>());
|
2023-04-02 13:17:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace sherpa_onnx
|