From df602b900d9ceac7520ad6019f665d2bce98de2f Mon Sep 17 00:00:00 2001 From: filipi87 Date: Thu, 26 Mar 2026 10:39:44 -0300 Subject: [PATCH] Preventing a race condition in the InterruptibleTTSServices in cases where run_tts has been invoked but the BotStartedSpeakingFrame has not yet been received. --- src/pipecat/services/tts_service.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pipecat/services/tts_service.py b/src/pipecat/services/tts_service.py index 8195b4f86..1e34ab79a 100644 --- a/src/pipecat/services/tts_service.py +++ b/src/pipecat/services/tts_service.py @@ -1509,6 +1509,20 @@ class InterruptibleTTSService(WebsocketTTSService): await self._disconnect() await self._connect() + async def push_frame(self, frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM): + """Push a frame downstream with TTS-specific handling. + + Args: + frame: The frame to push. + direction: The direction to push the frame. + """ + # This prevents a race condition in cases where run_tts has been invoked but the + # BotStartedSpeakingFrame has not yet been received, which could allow stale audio to leak through. + if isinstance(frame, TTSStartedFrame): + self._bot_speaking = True + + await super().push_frame(frame, direction) + async def process_frame(self, frame: Frame, direction: FrameDirection): """Process frames with bot speaking state tracking.