|
@@ -176,6 +176,7 @@ class MyCall(pj.Call):
|
|
|
def __init__(self, agent, acc, user_part, call_id, **kwargs):
|
|
|
pj.Call.__init__(self, acc, call_id)
|
|
|
self.agent = agent
|
|
|
+ self.logger = agent.logger
|
|
|
self.user_part = user_part
|
|
|
self.call_id = call_id
|
|
|
self.kwargs = kwargs
|
|
@@ -186,7 +187,7 @@ class MyCall(pj.Call):
|
|
|
self.session_id = kwargs.get('variable_sip_h_P-LIBRA-CallId')
|
|
|
self.device_id = kwargs.get('variable_sip_h_P-LIBRA-DeviceId')
|
|
|
|
|
|
- print("self.session_id:", self.session_id)
|
|
|
+ self.logger.info("self.session_id:%s", self.session_id)
|
|
|
# self.scripts = build_demo_script()
|
|
|
self.user_asr_text_queue = queue.Queue(maxsize=100)
|
|
|
self.message_queue = queue.Queue(maxsize=3)
|
|
@@ -241,7 +242,7 @@ class MyCall(pj.Call):
|
|
|
call_info = self.getInfo()
|
|
|
match = re.match(r'"(\d+)" <sip:(\d+)@', call_info.remoteUri)
|
|
|
if match:
|
|
|
- print("Phone Number:", match.group(1))
|
|
|
+ self.logger.info("Phone Number:%s", match.group(1))
|
|
|
return match.group(1), call_info.callIdString # 假设显示名称部分是手机号
|
|
|
else:
|
|
|
return "", call_info.callIdString
|
|
@@ -268,7 +269,7 @@ class MyCall(pj.Call):
|
|
|
|
|
|
def onCallState(self, prm):
|
|
|
call_info = self.getInfo()
|
|
|
- print("Call state: %s, call id: %s, callcallIdString: %s ", call_info.state, call_info.id, call_info.callIdString)
|
|
|
+ self.logger.info("Call state: %s, call id: %s, callcallIdString: %s ", call_info.state, call_info.id, call_info.callIdString)
|
|
|
|
|
|
# pj.PJSIP_INV_STATE_NULL
|
|
|
# pj.PJSIP_INV_STATE_CALLING
|
|
@@ -283,7 +284,7 @@ class MyCall(pj.Call):
|
|
|
self.bot_say_hello()
|
|
|
|
|
|
if call_info.state == pj.PJSIP_INV_STATE_DISCONNECTED:
|
|
|
- print("通话结束", self.user_part)
|
|
|
+ self.logger.info("通话结束:%s", self.user_part)
|
|
|
if self.audio_port:
|
|
|
self.audio_port = None # 或调用相关销毁方法
|
|
|
if self.player:
|
|
@@ -297,7 +298,7 @@ class MyCall(pj.Call):
|
|
|
for media in call_info.media:
|
|
|
if media.type == pj.PJMEDIA_TYPE_AUDIO and \
|
|
|
(media.status == pj.PJSUA_CALL_MEDIA_ACTIVE):
|
|
|
- print("Call Media state 111: ", call_info.stateText)
|
|
|
+ self.logger.info("Call Media state 111: %s", call_info.stateText)
|
|
|
self.aud_med = self.getAudioMedia(media.index)
|
|
|
try:
|
|
|
# 建立双向通道
|
|
@@ -317,7 +318,7 @@ class MyCall(pj.Call):
|
|
|
player_id = murmur3_32(player_file)
|
|
|
self.player_complete_dict[player_id] = False
|
|
|
# print('self.player_complete_dict[player_id]D:', player_id, player_file, self.player_complete_dict[player_id])
|
|
|
- print(f"[DEBUG] Sending bot speaker, player_file: {player_file}, player_id: {player_id}")
|
|
|
+ self.logger.info(f"[DEBUG] Sending bot speaker, player_file: {player_file}, player_id: {player_id}")
|
|
|
self.player = MyAudioMediaPlayer(player_id, self.aud_med, on_complete=self.on_media_player_complete)
|
|
|
# self.player.createPlayer(player_file[0], pj.PJMEDIA_FILE_NO_LOOP)
|
|
|
self.player.createPlaylist(player_file, f'my_hello_playlist{player_id}', pj.PJMEDIA_FILE_NO_LOOP)
|
|
@@ -331,17 +332,17 @@ class MyCall(pj.Call):
|
|
|
if message["header"]["status"] == 20000000:
|
|
|
if message["header"]["name"] == "SentenceEnd":
|
|
|
result = message["payload"]["result"]
|
|
|
- print("asr返回内容Result:", result)
|
|
|
+ self.logger.info("asr返回内容Result:%s", result)
|
|
|
self.user_asr_text_queue.put(result)
|
|
|
elif message["header"]["name"] == "TranscriptionResultChanged":
|
|
|
self.reset_wait_time()
|
|
|
else:
|
|
|
- print(f"Status is not {message['header']['status']}")
|
|
|
+ self.logger.info(f"Status is not {message['header']['status']}")
|
|
|
|
|
|
|
|
|
|
|
|
def on_media_player_complete(self, player_id):
|
|
|
- print('player complete')
|
|
|
+ self.logger.info('player complete')
|
|
|
self.player_complete_dict[player_id] = True
|
|
|
self.digit = ''
|
|
|
self.inputLongStart = time.time()
|
|
@@ -357,14 +358,14 @@ class MyCall(pj.Call):
|
|
|
ToTextBotAgent(user_asr_text,self)
|
|
|
|
|
|
def say_end_action(self, action):
|
|
|
- print('handling_release', action.action_code)
|
|
|
+ self.logger.info('handling_release %s', action.action_code)
|
|
|
action_code = action.action_code
|
|
|
if action_code == 'hang': # 挂断
|
|
|
action_content = action.action_content
|
|
|
- print(f'todo 挂电话:{action_content}')
|
|
|
+ self.logger.info(f'todo 挂电话:{action_content}')
|
|
|
self.agent.hangup(self.user_part)
|
|
|
elif action_code == 'transfer': # 转人工
|
|
|
- print('todo 转人工')
|
|
|
+ self.logger.info('todo 转人工')
|
|
|
self.agent.transfer(user_part=self.user_part, call_id=self.session_id, device_id=self.device_id)
|
|
|
#更新通话记录
|
|
|
self.agent.dataHandleServer.update_record(self.session_id, service_category=2)
|
|
@@ -487,6 +488,7 @@ class ToTextBotAgent:
|
|
|
class BotAgent:
|
|
|
|
|
|
def __init__(self, app, user_part_range=range(1001, 1011), host=SIP_SERVER, port="5060", password="slibra@#123456"):
|
|
|
+ self.app = app
|
|
|
self.logger = app.logger
|
|
|
self.user_part_range, self.host, self.port, self.password = user_part_range, host, port, password
|
|
|
self.user_part_pool = queue.Queue(maxsize=len(user_part_range))
|