Implemented tokens and timestamps in Python API (#205)

This commit is contained in:
Wilson Wongso
2023-07-12 08:12:31 +07:00
committed by GitHub
parent 0b5fa24134
commit b2364b0374
2 changed files with 12 additions and 1 deletions

View File

@@ -14,7 +14,12 @@ namespace sherpa_onnx {
static void PybindOnlineRecognizerResult(py::module *m) {
using PyClass = OnlineRecognizerResult;
py::class_<PyClass>(*m, "OnlineRecognizerResult")
.def_property_readonly("text", [](PyClass &self) { return self.text; });
.def_property_readonly(
"text", [](PyClass &self) -> std::string { return self.text; })
.def_property_readonly(
"tokens", [](PyClass &self) -> std::vector<std::string> { return self.tokens; })
.def_property_readonly(
"timestamps", [](PyClass &self) -> std::vector<float> { return self.timestamps; });
}
static void PybindOnlineRecognizerConfig(py::module *m) {

View File

@@ -149,6 +149,12 @@ class OnlineRecognizer(object):
def get_result(self, s: OnlineStream) -> str:
return self.recognizer.get_result(s).text.strip()
def tokens(self, s: OnlineStream) -> List[str]:
return self.recognizer.get_result(s).tokens
def timestamps(self, s: OnlineStream) -> List[float]:
return self.recognizer.get_result(s).timestamps
def is_endpoint(self, s: OnlineStream) -> bool:
return self.recognizer.is_endpoint(s)