Flush output from TTSService on LLMFullResponseEndFrame

To cover cases when the LLM response does not end in punctuation.
This commit is contained in:
Lewis Wolfgang
2024-06-22 14:57:44 -04:00
committed by Ubuntu
parent 4c20ce20f6
commit e4967107b2

View File

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