From db577ae13d02389c1e7a05e4883fef000b466471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 6 Jun 2024 14:06:01 -0700 Subject: [PATCH] transports: allow sending metrics --- src/pipecat/transports/base_output.py | 6 ++++++ src/pipecat/transports/services/daily.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/pipecat/transports/base_output.py b/src/pipecat/transports/base_output.py index b81f2f8db..4c19a0b55 100644 --- a/src/pipecat/transports/base_output.py +++ b/src/pipecat/transports/base_output.py @@ -20,6 +20,7 @@ from pipecat.frames.frames import ( AudioRawFrame, CancelFrame, + MetricsFrame, SpriteFrame, StartFrame, EndFrame, @@ -87,6 +88,9 @@ async def stop(self): def send_message(self, frame: TransportMessageFrame): pass + def send_metrics(self, frame: MetricsFrame): + pass + def write_frame_to_camera(self, frame: ImageRawFrame): pass @@ -166,6 +170,8 @@ def _sink_thread_handler(self): self._set_camera_images(frame.images) elif isinstance(frame, TransportMessageFrame): self.send_message(frame) + elif isinstance(frame, MetricsFrame): + self.send_metrics(frame) else: future = asyncio.run_coroutine_threadsafe( self._internal_push_frame(frame), self.get_event_loop()) diff --git a/src/pipecat/transports/services/daily.py b/src/pipecat/transports/services/daily.py index 8e42a1678..3336814d9 100644 --- a/src/pipecat/transports/services/daily.py +++ b/src/pipecat/transports/services/daily.py @@ -27,6 +27,7 @@ Frame, ImageRawFrame, InterimTranscriptionFrame, + MetricsFrame, SpriteFrame, StartFrame, TranscriptionFrame, @@ -638,6 +639,15 @@ async def cleanup(self): def send_message(self, frame: DailyTransportMessageFrame): self._client.send_message(frame) + def send_metrics(self, frame: MetricsFrame): + message = DailyTransportMessageFrame(message={ + "type": "pipecat-metrics", + "metrics": { + "ttfb": frame.ttfb + }, + }) + self._client.send_message(message) + def write_raw_audio_frames(self, frames: bytes): self._client.write_raw_audio_frames(frames)