From 1a66bdef8ed36722169752041051a62d844f85a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 12 Mar 2026 00:15:03 -0700 Subject: [PATCH] Fix TTS stop ordering to drain audio contexts before canceling Wait for _audio_context_task to finish draining the contexts queue before canceling _stop_frame_task, ensuring all pending audio contexts are processed during shutdown. --- src/pipecat/services/tts_service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pipecat/services/tts_service.py b/src/pipecat/services/tts_service.py index da1bcaf87..7cfb9d738 100644 --- a/src/pipecat/services/tts_service.py +++ b/src/pipecat/services/tts_service.py @@ -536,15 +536,15 @@ class TTSService(AIService): frame: The end frame. """ await super().stop(frame) - if self._stop_frame_task: - await self.cancel_task(self._stop_frame_task) - self._stop_frame_task = None if self._audio_context_task: # Indicate no more audio contexts are available; this will end the # task cleanly after all contexts have been processed. await self._contexts_queue.put(None) await self._audio_context_task self._audio_context_task = None + if self._stop_frame_task: + await self.cancel_task(self._stop_frame_task) + self._stop_frame_task = None async def cancel(self, frame: CancelFrame): """Cancel the TTS service.