774056846 4 months ago
parent
commit
a4bd12f111
2 changed files with 11 additions and 11 deletions
  1. 4 5
      src/core/voip/asr.py
  2. 7 6
      src/core/voip/bot.py

+ 4 - 5
src/core/voip/asr.py

@@ -67,11 +67,10 @@ class TestSt:
             print("无法获取Token")
             return None
 
-    def __init__(self, tid, message_receiver=None, begin_callback=None):
+    def __init__(self, tid, message_receiver=None):
         self.__th = threading.Thread(target=self.__test_run)
         self.__id = tid
         self.message_receiver = message_receiver
-        self.begin_callback = begin_callback
         self._Token = self.get_cached_token()
         self.sr = None
         print("开始")
@@ -111,9 +110,9 @@ class TestSt:
 
     def test_on_sentence_begin(self, message, *args):
         # pass
-        print("test_on_sentence_begin:{}".format(message))
-        if self.begin_callback:
-            self.begin_callback(message, *args)
+        # print("test_on_sentence_begin:{}".format(message))
+        if self.message_receiver:
+            self.message_receiver(message, *args)
 
     def test_on_sentence_end(self, message, *args):
         # print("test_on_sentence_end:{}".format(message))

+ 7 - 6
src/core/voip/bot.py

@@ -320,16 +320,17 @@ class MyCall(pj.Call):
         self.player.startTransmit(self.aud_med)
 
     def on_receiver_asr_result(self, message, *args):
-        if not self.txtLock:   # 判断是否播放完成 否则不记录用户说的内容
-            self.reset_wait_time()
-            message = json.loads(message)
-            if message["header"]["status"] == 20000000:
-                # 获取 result 内容
+        # if not self.txtLock:   # 判断是否播放完成 否则不记录用户说的内容
+        message = json.loads(message)
+        if message["header"]["status"] == 20000000:
+            if message["header"]["name"] == "SentenceEnd":
                 result = message["payload"]["result"]
                 print("asr返回内容Result:", result)
                 self.user_asr_text_queue.put(result)
             else:
-                print(f"Status is not {message['header']['status']}")
+                self.reset_wait_time()
+        else:
+            print(f"Status is not {message['header']['status']}")