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:
committed by
Mark Backman
parent
98d3f697f1
commit
3c90468e03
1
changelog/4071.fixed.md
Normal file
1
changelog/4071.fixed.md
Normal 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.
|
||||||
@@ -720,11 +720,6 @@ class TTSService(AIService):
|
|||||||
self._turn_context_id = self.create_context_id()
|
self._turn_context_id = self.create_context_id()
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
elif isinstance(frame, (LLMFullResponseEndFrame, EndFrame)):
|
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)
|
# Flush any remaining text (including text waiting for lookahead)
|
||||||
remaining = await self._text_aggregator.flush()
|
remaining = await self._text_aggregator.flush()
|
||||||
# Stop the aggregation metric (no-op if already stopped on first sentence).
|
# Stop the aggregation metric (no-op if already stopped on first sentence).
|
||||||
@@ -732,6 +727,11 @@ class TTSService(AIService):
|
|||||||
if remaining:
|
if remaining:
|
||||||
await self._push_tts_frames(AggregatedTextFrame(remaining.text, remaining.type))
|
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.
|
# Log accumulated streamed text and emit aggregated usage metric.
|
||||||
if self._streamed_text:
|
if self._streamed_text:
|
||||||
logger.debug(f"{self}: Generating TTS [{self._streamed_text}]")
|
logger.debug(f"{self}: Generating TTS [{self._streamed_text}]")
|
||||||
|
|||||||
Reference in New Issue
Block a user