From e4967107b2f24b0c0fbe07e408b18faf03ff63d5 Mon Sep 17 00:00:00 2001 From: Lewis Wolfgang Date: Sat, 22 Jun 2024 14:57:44 -0400 Subject: [PATCH] Flush output from TTSService on LLMFullResponseEndFrame To cover cases when the LLM response does not end in punctuation. --- src/pipecat/services/ai_services.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pipecat/services/ai_services.py b/src/pipecat/services/ai_services.py index 308ffc7dc..527f597da 100644 --- a/src/pipecat/services/ai_services.py +++ b/src/pipecat/services/ai_services.py @@ -23,6 +23,7 @@ from pipecat.frames.frames import ( TTSStoppedFrame, TextFrame, VisionImageRawFrame, + LLMFullResponseEndFrame, ) from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from pipecat.utils.audio import calculate_audio_volume @@ -145,6 +146,11 @@ class TTSService(AIService): self._current_sentence = "" await self._push_tts_frames(self._current_sentence) await self.push_frame(frame) + elif isinstance(frame, LLMFullResponseEndFrame): + if self._current_sentence: + await self._push_tts_frames(self._current_sentence.strip()) + self._current_sentence = "" + await self.push_frame(frame) else: await self.push_frame(frame, direction)