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:
@@ -536,15 +536,15 @@ class TTSService(AIService):
|
|||||||
frame: The end frame.
|
frame: The end frame.
|
||||||
"""
|
"""
|
||||||
await super().stop(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:
|
if self._audio_context_task:
|
||||||
# Indicate no more audio contexts are available; this will end the
|
# Indicate no more audio contexts are available; this will end the
|
||||||
# task cleanly after all contexts have been processed.
|
# task cleanly after all contexts have been processed.
|
||||||
await self._contexts_queue.put(None)
|
await self._contexts_queue.put(None)
|
||||||
await self._audio_context_task
|
await self._audio_context_task
|
||||||
self._audio_context_task = None
|
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):
|
async def cancel(self, frame: CancelFrame):
|
||||||
"""Cancel the TTS service.
|
"""Cancel the TTS service.
|
||||||
|
|||||||
Reference in New Issue
Block a user