From 72d503d3a3a1561e68e042239d1571ad3db7e132 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 3 Jul 2025 10:48:26 -0300 Subject: [PATCH] Azure TTS fixed by clearing the audio queue before synthesizing the next text --- CHANGELOG.md | 3 +++ src/pipecat/services/azure/tts.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b34a057b8..bbfc5d304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue where audio would get stuck in the queue when an interrupt occurs + during Azure TTS synthesis. + - Fixed a race condition that occurs in Python 3.10+ where the task could miss the `CancelledError` and continue running indefinitely, freezing the pipeline. diff --git a/src/pipecat/services/azure/tts.py b/src/pipecat/services/azure/tts.py index 07e706a9b..0cf029c6b 100644 --- a/src/pipecat/services/azure/tts.py +++ b/src/pipecat/services/azure/tts.py @@ -282,6 +282,13 @@ class AzureTTSService(AzureBaseTTSService): """ logger.debug(f"{self}: Generating TTS [{text}]") + # Clear the audio queue in case there's still audio in it, causing the next audio response + # to be cut off by the 'None' element returned at the end of the previous audio synthesis. + # Empty the audio queue before processing the new text + while not self._audio_queue.empty(): + self._audio_queue.get_nowait() + self._audio_queue.task_done() + try: if self._speech_synthesizer is None: error_msg = "Speech synthesizer not initialized."