From cf2f4b59021dfa5c1d7aebf9df33e8f3a372f83e Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Sat, 7 Jun 2025 22:48:05 -0400 Subject: [PATCH] fix: ElevenLabsTTSService reset context when flushing audio --- CHANGELOG.md | 3 +++ src/pipecat/services/elevenlabs/tts.py | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f8930f44..89c9f3ff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) - Fixed an issue with various TTS services that would cause audio glitches at the start of every bot turn. +- Fixed an `ElevenLabsTTSService` issue where a context warning was printed + when pushing a `TTSSpeakFrame`. + - Fixed an `AssemblyAISTTService` issue that could cause unexpected behavior when yielding empty `Frame()`s. diff --git a/src/pipecat/services/elevenlabs/tts.py b/src/pipecat/services/elevenlabs/tts.py index 24357d48a..37261a4ef 100644 --- a/src/pipecat/services/elevenlabs/tts.py +++ b/src/pipecat/services/elevenlabs/tts.py @@ -279,9 +279,12 @@ class ElevenLabsTTSService(AudioContextWordTTSService): await self._disconnect() async def flush_audio(self): - if self._websocket and self._context_id: - msg = {"context_id": self._context_id, "flush": True} - await self._websocket.send(json.dumps(msg)) + if not self._context_id or not self._websocket: + return + logger.trace(f"{self}: flushing audio") + msg = {"context_id": self._context_id, "flush": True} + await self._websocket.send(json.dumps(msg)) + self._context_id = None async def push_frame(self, frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM): await super().push_frame(frame, direction)