Ver código fonte

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

DavidLiu 3 meses atrás
pai
commit
9ed6de1716

+ 1 - 1
Dockerfile

@@ -1,6 +1,6 @@
 FROM python:3.9
 RUN apt-get update && \
-    apt-get install -y vim wget curl sngrep tcpflow tcpdump && \
+    apt-get install -y vim wget curl sngrep tcpflow tcpdump ffmpeg&& \
     pip3 install swig cython pip setuptools --upgrade
 
 

+ 1 - 0
requirements.txt

@@ -10,3 +10,4 @@ gevent
 flask_sqlalchemy
 prometheus_client
 prometheus_flask_exporter
+pydub

+ 26 - 2
src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -3,7 +3,9 @@
 
 import json
 import sys
+import os
 import traceback
+from pydub import AudioSegment
 
 from src.core.callcenter.acd import AcdService
 from src.core.callcenter.call import CallService
@@ -125,10 +127,32 @@ class ChannelHangupHandler(EslEventHandler):
 
     def get_call_info_record(self, call_info):
         records = []
-        self.logger.info("1223232 %s", records)
         for value in call_info.device_info_map.values():
-            records.append(value.record)
+            records.append(value.record) if value.record else None
         self.logger.info("get_call_info_record: %s", records)
+        if records:
+            self.merge_audio_files(records)
+        else:
+            self.logger.warning("没有找到有效的录音文件")
+
+    def merge_audio_files(self,audio_files):
+        if not audio_files:
+            print("没有可合并的音频文件")
+            return
+            # 初始化第一个音频文件
+        combined = AudioSegment.from_file(audio_files[0])
+        # 循环添加其余的音频文件
+        for audio_file in audio_files[1:]:
+            next_audio = AudioSegment.from_file(audio_file)
+            combined += next_audio  # 拼接音频
+
+        first_file = audio_files[0]
+        dir_name = os.path.dirname(first_file)
+        base_name, ext = os.path.splitext(os.path.basename(first_file))
+        output_file = os.path.join(dir_name, f"{base_name}_merge{ext}")
+        # 导出合并后的音频文件
+        combined.export(output_file, format=ext.lstrip('.'))
+        print(f"音频合并完成: {output_file}")
     def release(self, event):
         device_id = event.getHeader("Unique-ID")
         user_part = self.cache.get_user_part(device_id)