From 0e533d21be49676c42c93efb3ec3df97384a71f5 Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Mon, 4 Aug 2025 10:52:30 -0300 Subject: [PATCH] Only send audio and video from the tavus video service if the transport is ready. --- src/pipecat/services/tavus/video.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pipecat/services/tavus/video.py b/src/pipecat/services/tavus/video.py index f9ba2833b..37b21257f 100644 --- a/src/pipecat/services/tavus/video.py +++ b/src/pipecat/services/tavus/video.py @@ -24,6 +24,7 @@ from pipecat.frames.frames import ( Frame, OutputAudioRawFrame, OutputImageRawFrame, + OutputTransportReadyFrame, StartFrame, StartInterruptionFrame, TTSAudioRawFrame, @@ -81,6 +82,7 @@ class TavusVideoService(AIService): self._send_task: Optional[asyncio.Task] = None # This is the custom track destination expected by Tavus self._transport_destination: Optional[str] = "stream" + self._transport_ready = False async def setup(self, setup: FrameProcessorSetup): """Set up the Tavus video service. @@ -145,7 +147,8 @@ class TavusVideoService(AIService): format=video_frame.color_format, ) frame.transport_source = video_source - await self.push_frame(frame) + if self._transport_ready: + await self.push_frame(frame) async def _on_participant_audio_data( self, participant_id: str, audio: AudioData, audio_source: str @@ -157,7 +160,8 @@ class TavusVideoService(AIService): num_channels=audio.num_channels, ) frame.transport_source = audio_source - await self.push_frame(frame) + if self._transport_ready: + await self.push_frame(frame) def can_generate_metrics(self) -> bool: """Check if this service can generate processing metrics. @@ -221,6 +225,9 @@ class TavusVideoService(AIService): await self.push_frame(frame, direction) elif isinstance(frame, TTSAudioRawFrame): await self._handle_audio_frame(frame) + elif isinstance(frame, OutputTransportReadyFrame): + self._transport_ready = True + await self.push_frame(frame, direction) else: await self.push_frame(frame, direction)