Azure TTS fixed by clearing the audio queue before synthesizing the next text

This commit is contained in:
Victor
2025-07-03 10:48:26 -03:00
committed by Filipi Fuchter
parent 453a904290
commit 72d503d3a3
2 changed files with 10 additions and 0 deletions

View File

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

View File

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