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.
This commit is contained in:
Aleix Conchillo Flaqué
2026-03-12 00:15:03 -07:00
parent 73a56f5d81
commit 1a66bdef8e

View File

@@ -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.