Merge pull request #256 from pipecat-ai/aleix/tts-cleanup-when-interrupted
services(tts): strip before TTS and cleanup when interrupted
This commit is contained in:
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed an issue that could mix new LLM responses with previous ones when
|
||||||
|
handling interruptions.
|
||||||
|
|
||||||
- Fixed a Daily transport blocking situation that occurred while reading audio
|
- Fixed a Daily transport blocking situation that occurred while reading audio
|
||||||
frames after a participant left the room. Needs daily-python >= 0.10.1.
|
frames after a participant left the room. Needs daily-python >= 0.10.1.
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ from pipecat.frames.frames import (
|
|||||||
EndFrame,
|
EndFrame,
|
||||||
ErrorFrame,
|
ErrorFrame,
|
||||||
Frame,
|
Frame,
|
||||||
|
LLMFullResponseStartFrame,
|
||||||
StartFrame,
|
StartFrame,
|
||||||
|
StartInterruptionFrame,
|
||||||
TTSStartedFrame,
|
TTSStartedFrame,
|
||||||
TTSStoppedFrame,
|
TTSStoppedFrame,
|
||||||
TextFrame,
|
TextFrame,
|
||||||
@@ -114,13 +116,17 @@ class TTSService(AIService):
|
|||||||
if self._current_sentence.strip().endswith(
|
if self._current_sentence.strip().endswith(
|
||||||
(".", "?", "!")) and not self._current_sentence.strip().endswith(
|
(".", "?", "!")) and not self._current_sentence.strip().endswith(
|
||||||
("Mr,", "Mrs.", "Ms.", "Dr.")):
|
("Mr,", "Mrs.", "Ms.", "Dr.")):
|
||||||
text = self._current_sentence.strip()
|
text = self._current_sentence
|
||||||
self._current_sentence = ""
|
self._current_sentence = ""
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
await self._push_tts_frames(text)
|
await self._push_tts_frames(text)
|
||||||
|
|
||||||
async def _push_tts_frames(self, text: str):
|
async def _push_tts_frames(self, text: str):
|
||||||
|
text = text.strip()
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
|
|
||||||
await self.push_frame(TTSStartedFrame())
|
await self.push_frame(TTSStartedFrame())
|
||||||
await self.process_generator(self.run_tts(text))
|
await self.process_generator(self.run_tts(text))
|
||||||
await self.push_frame(TTSStoppedFrame())
|
await self.push_frame(TTSStoppedFrame())
|
||||||
@@ -133,14 +139,12 @@ class TTSService(AIService):
|
|||||||
|
|
||||||
if isinstance(frame, TextFrame):
|
if isinstance(frame, TextFrame):
|
||||||
await self._process_text_frame(frame)
|
await self._process_text_frame(frame)
|
||||||
elif isinstance(frame, EndFrame):
|
elif isinstance(frame, StartInterruptionFrame):
|
||||||
if self._current_sentence:
|
self._current_sentence = ""
|
||||||
await self._push_tts_frames(self._current_sentence)
|
await self.push_frame(frame, direction)
|
||||||
await self.push_frame(frame)
|
elif isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame):
|
||||||
elif isinstance(frame, LLMFullResponseEndFrame):
|
self._current_sentence = ""
|
||||||
if self._current_sentence:
|
await self._push_tts_frames(self._current_sentence)
|
||||||
await self._push_tts_frames(self._current_sentence.strip())
|
|
||||||
self._current_sentence = ""
|
|
||||||
await self.push_frame(frame)
|
await self.push_frame(frame)
|
||||||
else:
|
else:
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|||||||
Reference in New Issue
Block a user