diff --git a/src/pipecat/services/ai_services.py b/src/pipecat/services/ai_services.py index 023cabee8..f7a08802c 100644 --- a/src/pipecat/services/ai_services.py +++ b/src/pipecat/services/ai_services.py @@ -391,7 +391,6 @@ class WordTTSService(TTSService): def reset_word_timestamps(self): self._initial_word_timestamp = -1 - self._word_timestamps = [] async def add_word_timestamps(self, word_times: List[Tuple[str, float]]): for word, timestamp in word_times: @@ -426,7 +425,10 @@ class WordTTSService(TTSService): while True: try: (word, timestamp) = await self._words_queue.get() - if word == "LLMFullResponseEndFrame" and timestamp == 0: + if word == "Reset" and timestamp == 0: + self.reset_word_timestamps() + frame = None + elif word == "LLMFullResponseEndFrame" and timestamp == 0: frame = LLMFullResponseEndFrame() frame.pts = last_pts elif word == "TTSStoppedFrame" and timestamp == 0: @@ -435,8 +437,9 @@ class WordTTSService(TTSService): else: frame = TextFrame(word) frame.pts = self._initial_word_timestamp + timestamp - last_pts = frame.pts - await self.push_frame(frame) + if frame: + last_pts = frame.pts + await self.push_frame(frame) self._words_queue.task_done() except asyncio.CancelledError: break diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index 2449fede6..ff7b200c1 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -234,7 +234,7 @@ class CartesiaTTSService(WordTTSService): # timestamp to set send context frames. self._context_id = None await self.add_word_timestamps( - [("TTSStoppedFrame", 0), ("LLMFullResponseEndFrame", 0)] + [("TTSStoppedFrame", 0), ("LLMFullResponseEndFrame", 0), ("Reset", 0)] ) elif msg["type"] == "timestamps": await self.add_word_timestamps( diff --git a/src/pipecat/services/elevenlabs.py b/src/pipecat/services/elevenlabs.py index 4a9f80a44..9b1f54351 100644 --- a/src/pipecat/services/elevenlabs.py +++ b/src/pipecat/services/elevenlabs.py @@ -286,7 +286,7 @@ class ElevenLabsTTSService(WordTTSService): if isinstance(frame, (TTSStoppedFrame, StartInterruptionFrame)): self._started = False if isinstance(frame, TTSStoppedFrame): - await self.add_word_timestamps([("LLMFullResponseEndFrame", 0)]) + await self.add_word_timestamps([("LLMFullResponseEndFrame", 0), ("Reset", 0)]) async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction)