Jelajahi Sumber

fix: 修改语音逻辑

余尚辉 5 bulan lalu
induk
melakukan
f19a5f2ffa
3 mengubah file dengan 30 tambahan dan 33 penghapusan
  1. 1 2
      requirements.txt
  2. 1 1
      src/core/callcenter/esl/client.py
  3. 28 30
      src/core/voip/bot.py

+ 1 - 2
requirements.txt

@@ -7,5 +7,4 @@ gunicorn
 pymysql
 redis
 gevent
-flask_sqlalchemy
-aiohttp
+flask_sqlalchemy

+ 1 - 1
src/core/callcenter/esl/client.py

@@ -30,7 +30,7 @@ class InboundClient:
 
     def __init__(self, agent, logger):
         self.con = None
-        self.thread_num = 12
+        self.thread_num = 32
         self.is_stopping = False
         self.logger = logger
         self.bot_agent = agent

+ 28 - 30
src/core/voip/bot.py

@@ -85,13 +85,14 @@ class MyAudioMediaPort(pj.AudioMediaPort):
                 self.call.chat(user_asr_text)
 
             #超时处理
-            current_time = time.time()
             # print(f'onFrameReceived:self.wait_time={self.call.wait_time}, self.call.digit ={self.call.digit},asr_text:{asr_text},play_complete:{play_complete},self.call.inputType:{self.call.inputType}')
             if self.call.wait_time and self.call.wait_time != "0" and play_complete and not asr_text and not self.call.digit :
+                current_time = time.time()
                 self.wait_time_check(current_time, self.call.wait_time)
 
             # 如果为超长类型的按键服务 超过30s未输入完成执行超时操作
             if self.call.inputType == '1' and play_complete and not asr_text:
+                current_time = time.time()
                 self.wait_time_check(current_time, 30)
 
             message_queue_size = self.call.message_queue.qsize()
@@ -260,7 +261,7 @@ class MyCall(pj.Call):
 
     def onCallState(self, prm):
         call_info = self.getInfo()
-        print("Call state: ",call_info.state)
+        print("Call state: ", call_info.state)
 
         # pj.PJSIP_INV_STATE_NULL
         # pj.PJSIP_INV_STATE_CALLING
@@ -311,10 +312,7 @@ class MyCall(pj.Call):
         self.player.startTransmit(self.aud_med)
 
     def on_receiver_asr_result(self, message, *args):
-        if not self.is_play_complete():  # 判断是否播放完成 否则不记录用户说的内容
-            return
-
-        print('asr返回内容:',message)
+        # print('asr返回内容:',message)
         message = json.loads(message)
         if message["header"]["status"] == 20000000:
             # 获取 result 内容
@@ -357,7 +355,7 @@ class ToTextBotAgent:
         self.request_data = BotChatRequest(
             nodeId=self.call_agent.node_id,
             userId=self.call_agent.call_phone,
-            sessionId="1334343434",
+            sessionId=self.call_agent.call_id,
             recordId="",
             taskId="10001",
             asrText=user_asr_text,
@@ -401,52 +399,52 @@ class ToTextBotAgent:
     def test_request(self, params: BotChatRequest):
         print("test_request::params=", params)
         response_data = {
-            "nodeId": "1.0",
+            "node_id": "1.0",
             "contents": [],
-            "waitTime": "6",
+            "wait_time": "6",
             "action": {
-                "actionCode": "normal",
-                "actionContent": "正常通话"
+                "action_code": "normal",
+                "action_content": "正常通话"
             },
-            "inputType": "0"
+            "input_type": "0"
         }
 
         print("asrText:", params.asrText)
         if params.asrText == 'start':                              #欢迎语
             response_data['contents'].append({
-                "contentType": "voice",
+                "content_type": "voice",
                 "content": "",
-                "voiceUrl": '/code/src/core/voip/scripts/1_00.wav',
-                "voiceContent": "五一北京到上海的高铁票还有吗?"
+                "voice_url": '/code/src/core/voip/scripts/1_00.wav',
+                "voice_content": "五一北京到上海的高铁票还有吗?"
             })
             response_data['inputType'] = '1'
         elif params.asrText == 'ASR408error':                          #超时执行
             response_data['contents'].append({
-                "contentType": "voice",
+                "content_type": "voice",
                 "content": "",
-                "voiceUrl": '/code/src/core/voip/scripts/4_00.wav',
-                "voiceContent": "waitTime超时"
+                "voice_url": '/code/src/core/voip/scripts/4_00.wav',
+                "voice_content": "waitTime超时"
             })
         elif "DTMF" in params.asrText and self.call_agent.inputType =='1':   #长按键超30s执行
             response_data['contents'].append({
-                "contentType": "voice",
+                "content_type": "voice",
                 "content": "",
-                "voiceUrl": '/code/src/core/voip/scripts/2_00.wav',
-                "voiceContent": "sds"
+                "voice_url": '/code/src/core/voip/scripts/2_00.wav',
+                "voice_content": "sds"
             })
         else :
             response_data['contents'] = [
                 {
-                    "contentType": "voice",
+                    "content_type": "voice",
                     "content": "",
-                    "voiceUrl": '/code/src/core/voip/test111.wav',
-                    "voiceContent": "测试第二个录音文件"
+                    "voice_url": '/code/src/core/voip/test111.wav',
+                    "voice_content": "测试第二个录音文件"
                 },
                 {
-                    "contentType": "voice",
+                    "content_type": "voice",
                     "content": "",
-                    "voiceUrl": '/code/src/core/voip/test222.wav',
-                    "voiceContent": "五一北京到上海的高铁票还有吗?"
+                    "voice_url": '/code/src/core/voip/test222.wav',
+                    "voice_content": "五一北京到上海的高铁票还有吗?"
                 }
             ]
         try:
@@ -474,10 +472,10 @@ class BotAgent:
     def create_pjsua2(self):
         # Create and initialize the library
         ep_cfg = pj.EpConfig()
-        ep_cfg.uaConfig.threadCnt = 12
+        ep_cfg.uaConfig.threadCnt = 32
         ep_cfg.uaConfig.mainThreadOnly = False
-        ep_cfg.uaConfig.maxCalls = 12
-        ep_cfg.uaConfig.maxAccounts = 12
+        ep_cfg.uaConfig.maxCalls = 20
+        ep_cfg.uaConfig.maxAccounts = 20
         ep_cfg.medConfig.noVad = True
         ep_cfg.logConfig.level = 4
         ep_cfg.logConfig.consoleLevel = 4