Fixed the ordering of _maybe_pause_frame_processing call in TTSService (#4071)

* Fixing the invocation of pause_frame_processing at the correct time when receiving LLMFullResponseEndFrame and EndFrame.
This commit is contained in:
Filipi da Silva Fuchter
2026-03-18 16:55:59 -04:00
committed by GitHub
parent bad10177d4
commit 4aea7784c9
2 changed files with 6 additions and 5 deletions

1
changelog/4071.fixed.md Normal file
View File

@@ -0,0 +1 @@
- Fixed audio overlap and potential dropped TTS content when multiple assistant turns occur in quick succession. `TTSService` now flushes remaining text before pausing frame processing on `LLMFullResponseEndFrame`/`EndFrame`, instead of pausing first.

View File

@@ -720,11 +720,6 @@ class TTSService(AIService):
self._turn_context_id = self.create_context_id()
await self.push_frame(frame, direction)
elif isinstance(frame, (LLMFullResponseEndFrame, EndFrame)):
# We pause processing incoming frames if the LLM response included
# text (it might be that it's only a function calling response). We
# pause to avoid audio overlapping.
await self._maybe_pause_frame_processing()
# Flush any remaining text (including text waiting for lookahead)
remaining = await self._text_aggregator.flush()
# Stop the aggregation metric (no-op if already stopped on first sentence).
@@ -732,6 +727,11 @@ class TTSService(AIService):
if remaining:
await self._push_tts_frames(AggregatedTextFrame(remaining.text, remaining.type))
# We pause processing incoming frames if the LLM response included
# text (it might be that it's only a function calling response). We
# pause to avoid audio overlapping.
await self._maybe_pause_frame_processing()
# Log accumulated streamed text and emit aggregated usage metric.
if self._streamed_text:
logger.debug(f"{self}: Generating TTS [{self._streamed_text}]")