|
@@ -206,7 +206,7 @@ class XfAsr:
|
|
|
self.logger = logger
|
|
|
self.message_receiver = message_receiver
|
|
|
self.ws = self.new_connection()
|
|
|
- self.logger.info(f"xunfei.Asr: ws.connected:{self.ws.connected}")
|
|
|
+ self.logger.info(f"xunfei.Asr: call_id: {tid}, ws.connected:{self.ws.connected}")
|
|
|
self.trecv = threading.Thread(target=self.recv)
|
|
|
|
|
|
def new_connection(self, base_url = "ws://rtasr.xfyun.cn/v1/ws", app_id = "1ec1097b", api_key = "60b7d2d8d172b065b1c3e723e5ba0696"):
|
|
@@ -243,7 +243,7 @@ class XfAsr:
|
|
|
break
|
|
|
except Exception as e:
|
|
|
count -= 1
|
|
|
- self.logger.info("new_connection:exception, count=%s, message=%s", count, e)
|
|
|
+ self.logger.info("new_connection:exception, call_id: %s, count=%s, message=%s", self.tid, count, e)
|
|
|
time.sleep(.010)
|
|
|
return _ws
|
|
|
|
|
@@ -269,7 +269,7 @@ class XfAsr:
|
|
|
# print("send end tag success")
|
|
|
|
|
|
def send_audio(self, chunk):
|
|
|
- self.logger.warn('xunfei.Asr.send_audio:chunk:%s, %s', len(chunk), chunk)
|
|
|
+ self.logger.warn('xunfei.Asr.send_audio: call_id: %s, chunk:%s, %s', self.tid, len(chunk), chunk)
|
|
|
if self.ws:
|
|
|
self.ws.send(chunk)
|
|
|
|
|
@@ -277,21 +277,21 @@ class XfAsr:
|
|
|
if self.ws:
|
|
|
self.ws.send(bytes(self.end_tag.encode('utf-8')))
|
|
|
self.ws.close()
|
|
|
- print("connection closed")
|
|
|
+ self.logger.info("connection closed call_id: %s", self.tid)
|
|
|
|
|
|
def recv(self):
|
|
|
try:
|
|
|
# {"seg_id": 0, "cn": {"st": {"rt": [{"ws": [{"cw": [{"sc": 0.00, "w": "凭", "wp": "n", "rl": "0", "wb": 13, "wc": 0.00, "we": 26}], "wb": 0, "we": 0}]}], "bg": "9510", "type": "1", "ed": "0"}}, "ls": false}
|
|
|
# {"seg_id": 1, "cn": {"st": {"rt": [{"ws": [{"cw": [{"sc": 0.00, "w": "停水", "wp": "n", "rl": "0", "wb": 26, "wc": 0.00, "we": 52}], "wb": 0,"we": 0}]}], "bg": "9770", "type": "1", "ed": "0"}}, "ls": false}
|
|
|
# {"seg_id": 2, "cn": {"st": {"rt": [{"ws": [{"cw": [{"sc": 0.00, "w": "停水", "wp": "n", "rl": "0", "wb": 9, "wc": 0.00, "we": 64}], "wb": 9,"we": 64},{"cw": [{"sc": 0.00, "w": "咨询", "wp": "n", "rl": "0", "wb": 65, "wc": 0.00, "we": 132}], "wb": 65,"we": 132}]}], "bg": "9510", "type": "0", "ed": "10950"}}, "ls": false}
|
|
|
- self.logger.info(f"xunfei.Asr.recv: ws.connected:{self.ws.connected}")
|
|
|
+ self.logger.info(f"xunfei.Asr.recv: call_id: {self.tid}, ws.connected:{self.ws.connected}")
|
|
|
while self.ws and self.ws.connected:
|
|
|
message = str(self.ws.recv())
|
|
|
if len(message) == 0:
|
|
|
- self.logger.info("xunfei.Asr.recv: receive result end")
|
|
|
+ self.logger.info("xunfei.Asr.recv: receive result end call_id: %s", self.tid)
|
|
|
break
|
|
|
|
|
|
- self.logger.warn("xunfei.Asr.recv: message :%s", message)
|
|
|
+ self.logger.warn("xunfei.Asr.recv: call_id: %s, message :%s", self.tid, message)
|
|
|
if self.message_receiver:
|
|
|
self.message_receiver(self.convert_message(message))
|
|
|
|
|
@@ -314,7 +314,7 @@ class XfAsr:
|
|
|
# return
|
|
|
except Exception as e:
|
|
|
traceback.print_exc()
|
|
|
- self.logger.error("xunfei.Asr.recv: receive result end, %s", e)
|
|
|
+ self.logger.error("xunfei.Asr.recv: receive result end, call_id: %s, message: %s", self.tid, e)
|
|
|
|
|
|
def convert_message(self, message):
|
|
|
final_result = {}
|