Pārlūkot izejas kodu

讯飞asr测试,debug

Davidliu 1 mēnesi atpakaļ
vecāks
revīzija
e87f5d30aa
1 mainītis faili ar 21 papildinājumiem un 16 dzēšanām
  1. 21 16
      src/core/voip/asr.py

+ 21 - 16
src/core/voip/asr.py

@@ -316,23 +316,28 @@ class XfAsr:
     def convert_message(self, message):
         final_result = {}
         result_dict = json.loads(message)
-        if result_dict["action"] == "started":
-            final_result['name'] = 'SentenceBegin'
-        elif result_dict["action"] == "result":
-            result_dict = json.loads(message)
-            result_1 = json.loads(result_dict["data"])
-            st = result_1["cn"]["st"]
-            rt = st["rt"]
-            if st.get('type') == 1:
-                final_result['name'] = 'TranscriptionResultChanged'
-            else:
-                final_result['name'] = 'SentenceEnd'
-            final_result['result'] = ''.join(cw["w"] for item in rt for ws in item["ws"] for cw in ws["cw"])
-        elif result_dict["action"] == "error":
+        if result_dict["code"] == "0":
+            if result_dict["action"] == "started":
+                final_result['name'] = 'SentenceBegin'
+            elif result_dict["action"] == "result":
+                result_dict = json.loads(message)
+                result_1 = json.loads(result_dict["data"])
+                st = result_1["cn"]["st"]
+                rt = st["rt"]
+                self.logger.error("xunfei.Asr.recv: st.type: %s", st['type'])
+                if st['type'] == "1":
+                    final_result['name'] = 'TranscriptionResultChanged'
+                if st['type'] == "0":
+                    final_result['name'] = 'SentenceEnd'
+                final_result['result'] = ''.join(cw["w"] for item in rt for ws in item["ws"] for cw in ws["cw"])
+            elif result_dict["action"] == "error":
+                final_result['name'] = 'TranscriptionResultError'
+                final_result['result'] = message
+                if self.ws:
+                    self.ws.close()
+        else:
             final_result['name'] = 'TranscriptionResultError'
-            final_result['status'] = ''
-            final_result['result'] = message
+            final_result['status'] = result_dict["code"]
             if self.ws:
                 self.ws.close()
-
         return final_result