From 36190066ecbe4ca4ff2ccf71e6f23dee6963610b Mon Sep 17 00:00:00 2001 From: Freddy Boulton Date: Mon, 3 Feb 2025 15:16:16 -0500 Subject: [PATCH] code (#56) Co-authored-by: Freddy Boulton --- demo/video_send_output.py | 14 ++++++++------ docs/user-guide.md | 7 ++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/demo/video_send_output.py b/demo/video_send_output.py index eace5e6..51357eb 100644 --- a/demo/video_send_output.py +++ b/demo/video_send_output.py @@ -75,14 +75,16 @@ with gr.Blocks(css=css) as demo: with gr.Column(elem_classes=["my-column"]): with gr.Group(elem_classes=["my-group"]): image = WebRTC( - label="Stream", rtc_configuration=rtc_configuration, + label="Stream", + rtc_configuration=rtc_configuration, mode="send-receive", modality="video", - track_constraints={"width": {"exact": 800}, - "height": {"exact": 600}, - "aspectRatio": {"exact": 1.33333} - }, - rtp_params={"degradationPreference": "maintain-resolution"} + track_constraints={ + "width": {"exact": 800}, + "height": {"exact": 600}, + "aspectRatio": {"exact": 1.33333}, + }, + rtp_params={"degradationPreference": "maintain-resolution"}, ) conf_threshold = gr.Slider( label="Confidence Threshold", diff --git a/docs/user-guide.md b/docs/user-guide.md index e596c2e..e2cd946 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -200,6 +200,7 @@ Here is a complete example of using `AsyncStreamHandler` for using the Google Ge self.input_queue = asyncio.Queue() self.output_queue = asyncio.Queue() self.quit = asyncio.Event() + self.connected = asyncio.Event() def copy(self) -> "GeminiHandler": return GeminiHandler( @@ -219,6 +220,7 @@ Here is a complete example of using `AsyncStreamHandler` for using the Google Ge async with client.aio.live.connect( model="gemini-2.0-flash-exp", config=config ) as session: + self.connected.set() async for audio in session.start_stream( stream=self.stream(), mime_type="audio/pcm" ): @@ -240,7 +242,10 @@ Here is a complete example of using `AsyncStreamHandler` for using the Google Ge async def emit(self): if not self.args_set.is_set(): await self.wait_for_args() - asyncio.create_task(self.generator()) + + if not self.connected.is_set(): + asyncio.create_task(self.generator()) + await self.connected.wait() array = await self.output_queue.get() return (self.output_sample_rate, array)