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