Implemented tokens and timestamps in Python API (#205)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user