|
@@ -411,7 +411,8 @@ class XunfeiAsr:
|
|
|
status = XunfeiAsr.STATUS_FIRST_FRAME if first else XunfeiAsr.STATUS_CONTINUE_FRAME # 音频的状态信息,标识音频是第一帧,还是中间帧、最后一帧
|
|
|
if not audio_data:
|
|
|
status = XunfeiAsr.STATUS_LAST_FRAME
|
|
|
- self.logger.info('xunfei.Asr.send_audio: call_id: %s, status:%s, chunk:%s, %s', self.__id, status, len(audio_data), audio_data)
|
|
|
+ buf = bytes(audio_data) if audio_data else None
|
|
|
+ self.logger.info('xunfei.Asr.send_audio: call_id: %s, status:%s, chunk:%s, %s', self.__id, status, (len(buf) if buf else 0) , buf)
|
|
|
|
|
|
# 第一帧处理
|
|
|
# 发送第一帧音频,带business 参数
|
|
@@ -420,20 +421,20 @@ class XunfeiAsr:
|
|
|
d = {"common": self.CommonArgs,
|
|
|
"business": self.BusinessArgs,
|
|
|
"data": {"status": 0, "format": "audio/L16;rate=16000",
|
|
|
- "audio": str(base64.b64encode(audio_data), 'utf-8'),
|
|
|
+ "audio": str(base64.b64encode(buf), 'utf-8'),
|
|
|
"encoding": "raw"}}
|
|
|
d = json.dumps(d)
|
|
|
self.ws.send(d)
|
|
|
# 中间帧处理
|
|
|
elif status == XunfeiAsr.STATUS_CONTINUE_FRAME:
|
|
|
d = {"data": {"status": 1, "format": "audio/L16;rate=16000",
|
|
|
- "audio": str(base64.b64encode(audio_data), 'utf-8'),
|
|
|
+ "audio": str(base64.b64encode(buf), 'utf-8'),
|
|
|
"encoding": "raw"}}
|
|
|
self.ws.send(json.dumps(d))
|
|
|
# 最后一帧处理
|
|
|
elif status == XunfeiAsr.STATUS_LAST_FRAME:
|
|
|
d = {"data": {"status": 2, "format": "audio/L16;rate=16000",
|
|
|
- "audio": str(base64.b64encode(audio_data), 'utf-8'),
|
|
|
+ "audio": str(base64.b64encode(buf), 'utf-8'),
|
|
|
"encoding": "raw"}}
|
|
|
self.ws.send(json.dumps(d))
|
|
|
time.sleep(1)
|