From cc5009f368d84d1e3bf29e2b776ffdcec6bce49d Mon Sep 17 00:00:00 2001 From: IrvingGao <1729854488@qq.com> Date: Tue, 18 Jun 2024 22:18:31 +0800 Subject: [PATCH] [button] fix bugs --- takway/clients/web_socket_client_utils.py | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/takway/clients/web_socket_client_utils.py b/takway/clients/web_socket_client_utils.py index 93fa626..54a330a 100644 --- a/takway/clients/web_socket_client_utils.py +++ b/takway/clients/web_socket_client_utils.py @@ -365,14 +365,19 @@ class WebSocketClinet: break audio_dict = queue_data[1] - - client.send_per_data( - audio=audio_dict['frames'], - stream=True, - voice_synthesize=True, - is_end=audio_dict['is_end'], - encoding='base64', - ) + + try: + client.send_per_data( + audio=audio_dict['frames'], + stream=True, + voice_synthesize=True, + is_end=audio_dict['is_end'], + encoding='base64', + ) + except BrokenPipeError: + print(f"{datetime.now()}: web socket connection broken, skip send data.") + client.close_client() + break # is_end后切换播放模式 if audio_dict['is_end']: self.listening_event.clear() @@ -381,6 +386,10 @@ class WebSocketClinet: if not self.wakeup_event.is_set(): continue + if self.listening_event.is_set(): + print(f"{datetime.now()}: listening, skip setup web socket connection.") + continue + # 接收数据 while True: # 当唤醒状态被关闭时,退出循环