Browse Source

Implemented tokens, stokens, and timestamps in Python API (#225)

* Implemented tokens, stokens, and timestamps in Python API

* Fixed stokens Return Type
Wilson Wongso 2 năm trước cách đây
mục cha
commit
2d0f6a24f5

+ 7 - 1
sherpa-ncnn/python/csrc/recognizer.cc

@@ -45,7 +45,13 @@ static void PybindRecognitionResult(py::module *m) {
   using PyClass = RecognitionResult;
   py::class_<PyClass>(*m, "RecognitionResult")
       .def_property_readonly(
-          "text", [](PyClass &self) -> std::string { return self.text; });
+          "text", [](PyClass &self) -> std::string { return self.text; })
+      .def_property_readonly(
+          "tokens", [](PyClass &self) -> std::vector<int> { return self.tokens; })
+      .def_property_readonly(
+          "stokens", [](PyClass &self) -> std::vector<std::string> { return self.stokens; })
+      .def_property_readonly(
+          "timestamps", [](PyClass &self) -> std::vector<float> { return self.timestamps; });
 }
 
 static void PybindRecognizerConfig(py::module *m) {

+ 12 - 0
sherpa-ncnn/python/sherpa_ncnn/recognizer.py

@@ -225,6 +225,18 @@ class Recognizer(object):
     def text(self):
         return self.recognizer.get_result(self.stream).text
 
+    @property
+    def tokens(self):
+        return self.recognizer.get_result(self.stream).tokens
+
+    @property
+    def stokens(self):
+        return self.recognizer.get_result(self.stream).stokens
+
+    @property
+    def timestamps(self):
+        return self.recognizer.get_result(self.stream).timestamps
+
     @property
     def is_endpoint(self):
         return self.recognizer.is_endpoint(self.stream)