|
@@ -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)
|