DavidLiu 3 months ago
parent
commit
fea03dac4a
1 changed files with 14 additions and 9 deletions
  1. 14 9
      src/core/voip/bot.py

+ 14 - 9
src/core/voip/bot.py

@@ -280,13 +280,7 @@ class MyCall(pj.Call):
 
         if call_info.state == pj.PJSIP_INV_STATE_DISCONNECTED:
             self.logger.info("通话结束:%s", self.user_part)
-            if self.audio_port:
-                self.audio_port = None  # 或调用相关销毁方法
-            if self.player:
-                self.player = None  # 或调用播放器停止方法
-            # 远程挂机之后要将分机号回收
-            self.agent.release(self.user_part)
-            self.end_statistics()
+            self.call_end()
 
 
     def onCallMediaState(self, prm):
@@ -329,7 +323,7 @@ class MyCall(pj.Call):
         if message["header"]["status"] == 20000000:
             if message["header"]["name"] == "SentenceEnd":
                 result = message["payload"]["result"]
-                self.logger.info("asr返回内容Result:%s", result)
+                # self.logger.info("asr返回内容Result:%s", result)
                 self.user_asr_text_queue.put(result)
             elif message["header"]["name"] == "TranscriptionResultChanged":
                 self.reset_wait_time()
@@ -349,6 +343,7 @@ class MyCall(pj.Call):
 
     def bot_say_hello(self):
         self.chat(user_asr_text="start")
+
     def chat(self, user_asr_text=None):
         # 调用文本机器人接口
         ToTextBotAgent(user_asr_text,self)
@@ -372,6 +367,16 @@ class MyCall(pj.Call):
             registry.BOT_CALL_DURATION.labels(self.taskId).observe(latency)
             registry.BOT_INTERACTION_ROUNDS.labels(self.taskId).observe(self.inter_action_total)
 
+    def call_end(self):
+        if self.audio_port:
+            self.audio_port = None  # 或调用相关销毁方法
+        if self.player:
+            self.player = None  # 或调用播放器停止方法
+        self.asr.close()
+        # 远程挂机之后要将分机号回收
+        self.agent.release(self.user_part)
+        self.end_statistics()
+
 class ToTextBotAgent:
     def __init__(self, user_asr_text, call_agent):
         if not user_asr_text or (call_agent.action and call_agent.action.action_code != 'normal'):
@@ -403,7 +408,7 @@ class ToTextBotAgent:
         self.call_agent.logger.info(f"请求数据:{request_data},url:{url}")
         try:
             response = requests.post(url=url,  json=json.loads(request_data), headers=headers, timeout=10)  # 使用占位URL
-            self.call_agent.logger.info(f"原始响应内容:{response.text}")
+            self.call_agent.logger.info(f"chat::request:{request_data}, response:{response.text}")
             if response.status_code == 200:
                 response_data = response.json()
                 if "data" in response_data and response_data["code"]==0: