Skip to content

Commit 9aabd30

Browse files
Update gradio-voice to use fastrtc (#2093)
1 parent 94b879b commit 9aabd30

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

gemini/multimodal-live-api/gradio-voice/app.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import asyncio
22
import pathlib
3-
from typing import AsyncGenerator, Literal
3+
from typing import AsyncGenerator, Literal, cast
44

5+
from fastrtc import AsyncStreamHandler, WebRTC, async_aggregate_bytes_to_16bit
56
from google import genai
67
from google.genai.types import (
78
Content,
@@ -12,7 +13,6 @@
1213
VoiceConfig,
1314
)
1415
import gradio as gr
15-
from gradio_webrtc import AsyncStreamHandler, WebRTC, async_aggregate_bytes_to_16bit
1616
import numpy as np
1717

1818
current_dir = pathlib.Path(__file__).parent
@@ -41,7 +41,7 @@ def __init__(
4141
def copy(self) -> "GeminiHandler":
4242
"""Required implementation of the copy method for AsyncStreamHandler"""
4343
return GeminiHandler(
44-
expected_layout=self.expected_layout,
44+
expected_layout=cast(Literal["mono"], self.expected_layout),
4545
output_sample_rate=self.output_sample_rate,
4646
output_frame_size=self.output_frame_size,
4747
)
@@ -71,7 +71,13 @@ async def connect(
7171
)
7272
)
7373
),
74-
system_instruction=Content(parts=[Part.from_text(text=system_instruction)]),
74+
system_instruction=Content(
75+
parts=[
76+
Part.from_text(
77+
text=system_instruction or "You are a helpful assistant."
78+
)
79+
]
80+
),
7581
)
7682
async with client.aio.live.connect(
7783
model="gemini-2.0-flash-live-preview-04-09", config=config
@@ -153,7 +159,7 @@ def shutdown(self) -> None:
153159
mode="send-receive",
154160
# See for changes needed to deploy behind a firewall
155161
# https://fastrtc.org/deployment/
156-
rtc_configuration=None,
162+
rtc_configuration={},
157163
)
158164

159165
webrtc.stream(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
gradio>=5.12.0,<6.0
2-
gradio_webrtc
2+
fastrtc
33
librosa
44
google-genai==1.10.0

0 commit comments

Comments
 (0)