From d83c2b30930beac6a9812cd00329040015727ab8 Mon Sep 17 00:00:00 2001 From: Del Wang Date: Mon, 26 May 2025 21:39:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20tts=5Fend=20?= =?UTF-8?q?=E5=92=8C=20abort=20=E5=BE=AA=E7=8E=AF=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/xiaozhi/xiaozhi/event.py | 8 ++++++-- examples/xiaozhi/xiaozhi/xiaozhi.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/xiaozhi/xiaozhi/event.py b/examples/xiaozhi/xiaozhi/event.py index ef637b6..f10eafd 100644 --- a/examples/xiaozhi/xiaozhi/event.py +++ b/examples/xiaozhi/xiaozhi/event.py @@ -27,6 +27,7 @@ class __EventManager: self.session_id = 0 self.current_step = Step.idle self.next_step_future = None + self.tts_session_id = "" def update_step(self, step: Step, step_data=None): if get_xiaoai().mode == "xiaozhi": @@ -77,16 +78,19 @@ class __EventManager: self.update_step(Step.on_wakeup) self.start_session() - def on_tts_end(self): + def on_tts_end(self, session_id): """TTS结束""" if self.current_step == Step.on_interrupt: # 当前 session 已经被打断了,不再处理 return + if self.tts_session_id == session_id: + return + self.tts_session_id = session_id self.session_id = self.session_id + 1 self.update_step(Step.on_tts_end) self.start_session() - def on_tts_start(self): + def on_tts_start(self, session_id): """TTS结束""" self.update_step(Step.on_tts_start) diff --git a/examples/xiaozhi/xiaozhi/xiaozhi.py b/examples/xiaozhi/xiaozhi/xiaozhi.py index abfaf63..275dda5 100644 --- a/examples/xiaozhi/xiaozhi/xiaozhi.py +++ b/examples/xiaozhi/xiaozhi/xiaozhi.py @@ -296,10 +296,10 @@ class XiaoZhi: """处理TTS消息""" state = data.get("state", "") if state == "start": - EventManager.on_tts_start() + EventManager.on_tts_start(data.get("session_id")) self.schedule(lambda: self._handle_tts_start()) elif state == "stop": - EventManager.on_tts_end() + EventManager.on_tts_end(data.get("session_id")) self.schedule(lambda: self._handle_tts_stop()) elif state == "sentence_start": text = data.get("text", "")