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
parent 269d06aa15
commit c4a2d2197c

View File

@@ -21,6 +21,7 @@ from pipecat.frames.frames import (
TTSStoppedFrame, TTSStoppedFrame,
TextFrame, TextFrame,
VisionImageRawFrame, VisionImageRawFrame,
LLMFullResponseEndFrame,
) )
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.utils.audio import calculate_audio_volume from pipecat.utils.audio import calculate_audio_volume
@@ -136,6 +137,11 @@ class TTSService(AIService):
if self._current_sentence: if self._current_sentence:
await self._push_tts_frames(self._current_sentence) await self._push_tts_frames(self._current_sentence)
await self.push_frame(frame) 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: else:
await self.push_frame(frame, direction) await self.push_frame(frame, direction)