Explorar o código

Merge branch 'dev_20241205' of ssh://gitlab.fuxicarbon.com:1111/client_service/voice-gateway-service into dev_20241205

DavidLiu hai 3 meses
pai
achega
ccb526f8a8

+ 1 - 0
Dockerfile

@@ -14,6 +14,7 @@ RUN cd /code/pjproject/pjsip-apps/src/swig/python && make && make install
 RUN cd /code/python-ESL-1.4.18 && python setup.py install
 # nls
 RUN cd /code/alibabacloud-nls-python-sdk-dev && python -m pip install -r requirements.txt && python -m pip install .
+
 # 安装项目依赖
 RUN pip install -r requirements.txt
 

+ 4 - 1
alibabacloud-nls-python-sdk-dev/nls/websocket/_app.py

@@ -173,6 +173,7 @@ class WebSocketApp:
         self.last_pong_tm = 0
         self.subprotocols = subprotocols
         self.callback_args = callback_args
+        self.has_teardown = False
 
     def update_args(self, *args):
         self.callback_args = args
@@ -293,7 +294,9 @@ class WebSocketApp:
                 If close_frame is set, the on_close handler is invoked
                 with the statusCode and reason from the provided frame.
             """
-
+            if self.has_teardown:
+                return
+            self.has_teardown = True
             if thread and thread.is_alive():
                 event.set()
                 thread.join()

+ 1 - 1
alibabacloud-nls-python-sdk-dev/tests/test_tts.py

@@ -47,7 +47,7 @@ class TestTts:
         tts = nls.NlsSpeechSynthesizer(
                     token=TEST_ACCESS_TOKEN,
                     appkey=TEST_ACCESS_APPKEY,
-                    long_tts=True,
+                    long_tts=False,
                     on_metainfo=self.test_on_metainfo,
                     on_data=self.test_on_data,
                     on_completed=self.test_on_completed,

+ 2 - 1
docker-compose.yml

@@ -1,6 +1,6 @@
 services:
   pjsua:
-    image: pjsua2:v2.14.1203
+    image: pjsua2:v2.14.1206
     container_name: pjsua
     restart: always
 #    network_mode: host
@@ -8,6 +8,7 @@ services:
 #      - /Users/davidliu/git/voice-gateway-service:/code
       - /home/hongshan/voice-gateway-service:/code
       - /root/aibot/dm/voice:/root/aibot/dm/voice
+      - /home/hongshan/freeswitch:/freeswitch
     environment:
       - SERVE_HOST=192.168.100.159
       - TZ=Asia/Shanghai

+ 2 - 2
src/core/callcenter/agent.py

@@ -148,7 +148,7 @@ class AgentEventService:
 
                 self.agent_actionlog_service.insert_service_state(agent_monitor, AgentServiceState.REPROCESSING, AgentLogState.CHANNEL_HANG_UP)
 
-                self.data_handle_server.update_record(call_id, time_end=datetime.now())
+                # self.data_handle_server.update_record(call_id, time_end=datetime.now())
 
                 # 同步处理后处理置闲
                 # reprocessingIdle(statusDto);
@@ -222,7 +222,7 @@ class AgentEventService:
 
                 self.agent_actionlog_service.insert_service_state(agent_monitor, AgentServiceState.REPROCESSING,
                                                       AgentLogState.CHANNEL_HANG_UP, service_id=human_service_id)
-                self.data_handle_server.update_record(call_id, time_end=datetime.now())
+                # self.data_handle_server.update_record(call_id, time_end=datetime.now())
 
 
         except:

+ 3 - 0
src/core/callcenter/esl/handler/channel_answer_handler.py

@@ -160,6 +160,9 @@ class ChannelAnswerHandler(EslEventHandler):
                 _record_url = self.start_recording(device_id, get_record_file_name(call_id, CallStage.AGENT), call)
         else:
             _record_url = self.start_recording(device_id, get_record_file_name(call_id, CallStage.ALL), call)
+        device.record = _record_url
+        self.logger.info("luyincall:%s, device:%s" % (call, device))
+        self.cache.add_call_info(call)
         return _record_url
 
     def start_recording(self, device_id, file_name, call: CallInfo):

+ 6 - 6
src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -131,18 +131,18 @@ class ChannelHangupHandler(EslEventHandler):
             records.append(value.record) if value.record else None
         self.logger.info("get_call_info_record: %s", records)
         if records:
-           merge_record= self.merge_audio_files(records)
-           threading.Thread(target=self._update_record_in_thread, args=(call_info.session_id, merge_record)).start()
+           threading.Thread(target=self._update_record_in_thread, args=(call_info.call_id, records)).start()
         else:
             self.logger.warning("没有找到有效的录音文件")
 
-    def _update_record_in_thread(self, session_id, merge_record):
+    def _update_record_in_thread(self, call_id, records):
         """用于在独立线程中执行 update_record"""
         try:
-            self.dataHandleServer.update_record(session_id, record=merge_record)
-            self.logger.info("更新录音记录完成: session_id=%s", session_id)
+            merge_record = self.merge_audio_files(records) if len(records) > 1 else records[0]
+            self.dataHandleServer.update_record(call_id, time_end=datetime.now(), url=merge_record)
+            self.logger.info("更新录音记录完成: call_id=%s", call_id)
         except Exception as e:
-            self.logger.error("更新录音记录失败: session_id=%s, error=%s", session_id, str(e))
+            self.logger.error("更新录音记录失败: call_id=%s, error=%s", call_id, str(e))
     def merge_audio_files(self,audio_files):
         if not audio_files:
             self.logger.info("没有可合并的音频文件")

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

@@ -117,7 +117,7 @@ class MyAudioMediaPort(pj.AudioMediaPort):
     def get_asr_text(self):
         try:
             asr_text = self.call.user_asr_text_queue.get(block=False)
-            self.call.logger.info('get_asr_text:', asr_text)
+            self.call.logger.info('get_asr_text: %s', asr_text)
             return asr_text
         except:
             pass
@@ -371,7 +371,7 @@ class ToTextBotAgent:
             asrText=user_asr_text,
             ext= None
         )
-        self.call_agent.logger.info("user_asr_text发送结果:", user_asr_text)
+        self.call_agent.logger.info("user_asr_text发送结果: %s", user_asr_text)
         # 发送请求并处理响应
         # self.test_request(self.request_data)
         self.to_quest(self.request_data)
@@ -403,7 +403,7 @@ class ToTextBotAgent:
 
 # 模拟接口请求返回
     def test_request(self, params: BotChatRequest):
-        self.call_agent.logger.info("test_request::params=", params)
+        self.call_agent.logger.info("test_request::params= %s", params)
         response_data = {
             "node_id": "1.0",
             "contents": [],
@@ -415,7 +415,7 @@ class ToTextBotAgent:
             "inputType": "0"
         }
 
-        self.call_agent.logger.info("asrText:", params.asrText)
+        self.call_agent.logger.info("asrText: %s", params.asrText)
         if params.asrText == 'start':                              #欢迎语
             response_data['contents'].append({
                 "content_type": "voice",
@@ -454,7 +454,6 @@ class ToTextBotAgent:
                 }
             ]
         try:
-            self.call_agent.logger.info(json.dumps(response_data['contents']))
             parsed_response = ChatMessage.from_json(response_data)
             self.call_agent.message_queue.put(parsed_response)
         except Exception as e:
@@ -572,7 +571,7 @@ class BotAgent:
         acc = self.accounts.get(user_part)
         self.logger.info('register, user_part :%d, pool.size :%d', user_part, self.user_part_pool.qsize())
         if acc:
-            self.logger.info('register==========>', acc.getId())
+            self.logger.info('register==========> %s', acc.getId())
             # ps = pj.PresenceStatus()
             # ps.status = pj.PJSUA_BUDDY_STATUS_ONLINE
             # ps.activity = pj.PJRPID_ACTIVITY_AWAY