Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Browser_as_a_tool.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"\n",
"client = genai.Client(api_key=GOOGLE_API_KEY)\n",
"\n",
"LIVE_MODEL = 'gemini-2.5-flash-native-audio-preview-09-2025' # @param ['gemini-2.0-flash-live-001', 'gemini-live-2.5-flash-preview', 'gemini-2.5-flash-native-audio-preview-09-2025'] {allow-input: true, isTemplate: true}\n",
"LIVE_MODEL = 'gemini-3.1-flash-live-preview' # @param ['gemini-3.1-flash-live-preview'] {allow-input: true, isTemplate: true}\n",
"MODEL = 'gemini-2.5-flash' # @param ['gemini-2.5-flash'] {allow-input: true, isTemplate: true}"
]
},
Expand Down
7 changes: 3 additions & 4 deletions examples/LiveAPI_plotting_and_mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"outputs": [],
"source": [
"uri = f\"wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key={GOOGLE_API_KEY}\"\n",
"model = \"models/gemini-2.5-flash-native-audio-preview-09-2025\""
"model = \"models/gemini-3.1-flash-live-preview\""
]
},
{
Expand Down Expand Up @@ -247,9 +247,8 @@
"async def send(ws, prompt):\n",
" \"\"\"Send a user content message (only text is supported).\"\"\"\n",
" msg = {\n",
" \"client_content\": {\n",
" \"turns\": [{\"role\": \"user\", \"parts\": [{\"text\": prompt}]}],\n",
" \"turn_complete\": True,\n",
" \"realtime_input\": {\n",
" \"text\": prompt,\n",
" }\n",
" }\n",
" json_msg = json.dumps(msg)\n",
Expand Down
25 changes: 10 additions & 15 deletions examples/gradio_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class GeminiConfig:
def __init__(self):
self.api_key = os.getenv(KEY_NAME)
self.host = "generativelanguage.googleapis.com"
self.model = "models/gemini-3.1-flash-lite-preview"
self.ws_url = f"wss://{self.host}/ws/google.ai.generativelanguage.v1alpha.GenerativeService.BidiGenerateContent?key={self.api_key}"
self.model = "models/gemini-3.1-flash-live-preview"
self.ws_url = f"wss://{self.host}/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key={self.api_key}"

class AudioProcessor:
"""Handles encoding and decoding of audio data."""
Expand All @@ -81,12 +81,10 @@ def encode_audio(data, sample_rate):
encoded = base64.b64encode(data.tobytes()).decode("UTF-8")
return {
"realtimeInput": {
"mediaChunks": [
{
"mimeType": f"audio/pcm;rate={sample_rate}",
"data": encoded,
}
],
"audio": {
"mimeType": f"audio/pcm;rate={sample_rate}",
"data": encoded,
},
},
}

Expand Down Expand Up @@ -136,17 +134,14 @@ def receive(self, frame: tuple[int, np.ndarray]) -> None:
self._initialize_websocket()

sample_rate, array = frame
message = {"realtimeInput": {"mediaChunks": []}}
message = None

if sample_rate > 0 and array is not None:
array = array.squeeze()
audio_data = self.audio_processor.encode_audio(array, self.output_sample_rate)
message["realtimeInput"]["mediaChunks"].append({
"mimeType": f"audio/pcm;rate={self.output_sample_rate}",
"data": audio_data["realtimeInput"]["mediaChunks"][0]["data"],
})
message = audio_data

if message["realtimeInput"]["mediaChunks"]:
if message:
self.ws.send(json.dumps(message))
except Exception as e:
print(f"Error in receive: {str(e)}")
Expand Down Expand Up @@ -259,6 +254,6 @@ def registry(

# Launch the Gradio interface
gr.load(
name="gemini-3.1-flash-lite-preview",
name="gemini-3.1-flash-live-preview",
src=registry,
).launch()
63 changes: 6 additions & 57 deletions quickstarts/Get_started_LiveAPI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
},
"outputs": [],
"source": [
"MODEL = 'gemini-2.5-flash-native-audio-preview-09-2025' # @param ['gemini-2.0-flash-live-001', 'gemini-live-2.5-flash-preview', 'gemini-2.5-flash-native-audio-preview-09-2025'] {allow-input: true, isTemplate: true}"
"MODEL = 'gemini-3.1-flash-preview' # @param ['gemini-2.5-flash-native-audio-preview-12-2025'] {allow-input: true, isTemplate: true}"
]
},
{
Expand Down Expand Up @@ -227,54 +227,6 @@
"from google.genai import types"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jj7gDzfDOq4h"
},
"source": [
"## Text to Text\n",
"\n",
"The simplest way to use the Live API is as a text-to-text chat interface, but it can do **a lot** more than this."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"id": "dDfslcyIOqgI"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"> Hello? Gemini are you there? \n",
"\n",
"- Hello\n",
"- there! I am indeed here. How can I help you today?\n"
]
}
],
"source": [
"config={\n",
" \"response_modalities\": [\"TEXT\"]\n",
"}\n",
"\n",
"async with client.aio.live.connect(model=MODEL, config=config) as session:\n",
" message = \"Hello? Gemini are you there?\"\n",
" print(\"> \", message, \"\\n\")\n",
" await session.send_client_content(\n",
" turns={\"role\": \"user\", \"parts\": [{\"text\": message}]}, turn_complete=True\n",
" )\n",
"\n",
" # For text responses, When the model's turn is complete it breaks out of the loop.\n",
" turn = session.receive()\n",
" async for chunk in turn:\n",
" if chunk.text is not None:\n",
" print(f'- {chunk.text}')"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -373,8 +325,8 @@
" with wave_file(file_name) as wav:\n",
" message = \"Hello? Gemini are you there?\"\n",
" print(\"> \", message, \"\\n\")\n",
" await session.send_client_content(\n",
" turns={\"role\": \"user\", \"parts\": [{\"text\": message}]}, turn_complete=True\n",
" await session.send_realtime_input(\n",
" text=message\n",
" )\n",
"\n",
" turn = session.receive()\n",
Expand Down Expand Up @@ -493,8 +445,8 @@
" logger.debug('send')\n",
"\n",
" # Send the message to the model.\n",
" await self.session.send_client_content(\n",
" turns={\"role\": \"user\", \"parts\": [{\"text\": text}]}, turn_complete=True\n",
" await self.session.send_realtime_input(\n",
" text=text\n",
" )\n",
" logger.debug('sent')\n",
" yield text\n",
Expand Down Expand Up @@ -739,10 +691,7 @@
" message = await asyncio.to_thread(input, \"message > \")\n",
" if message.lower() == \"q\":\n",
" break\n",
" await session.send_client_content(turns={\n",
" 'role': 'user',\n",
" 'parts': [{'text': message}]\n",
" })\n",
" await session.send_realtime_input(text=message)\n",
"\n",
"\n",
"async def async_main(last_handle=None):\n",
Expand Down
9 changes: 4 additions & 5 deletions quickstarts/Get_started_LiveAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
CHUNK_SIZE = 1024

# --- Model Configuration ---
MODEL = "models/gemini-2.5-flash-native-audio-preview-12-2025"
MODEL = "models/gemini-3.1-flash-live-preview"
DEFAULT_MODE = "camera"


Expand Down Expand Up @@ -275,9 +275,8 @@ async def send_text(self):
if text.lower() == "q":
print("👋 Exiting on user request...")
break
await self.session.send_client_content(
turns=types.Content(parts=[types.Part(text=text or "")]),
turn_complete=True,
await self.session.send_realtime_input(
text=text or "",
)
except asyncio.CancelledError:
pass
Expand All @@ -289,7 +288,7 @@ async def send_realtime(self):
if msg["mime_type"].startswith("audio/"):
await self.session.send_realtime_input(audio=msg)
else:
await self.session.send_realtime_input(media=msg)
await self.session.send_realtime_input(video=msg)
except asyncio.CancelledError:
pass

Expand Down
3 changes: 1 addition & 2 deletions quickstarts/Get_started_LiveAPI_NativeAudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@
with an engaging follow-up question to keep the conversation flowing.
"""

MODEL = "gemini-2.5-flash-native-audio-preview-12-2025"
MODEL = "gemini-3.1-flash-live-preview"
CONFIG = {
"system_instruction": system_instruction,
"response_modalities": ["AUDIO"],
"proactivity": {'proactive_audio': True}
}


Expand Down
Loading
Loading