From 04d2f1a49dde981377864434d0f26160a1ee92b5 Mon Sep 17 00:00:00 2001 From: for_the_zero Date: Sat, 4 Oct 2025 17:21:53 +0800 Subject: [PATCH 1/2] Update Get_started_LiveAPI.py The file is outdated I copied the code from aistudio.google.com/live but it's alse outdated, it used some deprecated methods So I modified this it so that it could run expectedly --- quickstarts/Get_started_LiveAPI.py | 38 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/quickstarts/Get_started_LiveAPI.py b/quickstarts/Get_started_LiveAPI.py index ce6f7952d..708e6a62e 100755 --- a/quickstarts/Get_started_LiveAPI.py +++ b/quickstarts/Get_started_LiveAPI.py @@ -45,11 +45,10 @@ ``` """ +import os import asyncio import base64 import io -import os -import sys import traceback import cv2 @@ -60,12 +59,7 @@ import argparse from google import genai - -if sys.version_info < (3, 11, 0): - import taskgroup, exceptiongroup - - asyncio.TaskGroup = taskgroup.TaskGroup - asyncio.ExceptionGroup = exceptiongroup.ExceptionGroup +from google.genai import types FORMAT = pyaudio.paInt16 CHANNELS = 1 @@ -73,13 +67,31 @@ RECEIVE_SAMPLE_RATE = 24000 CHUNK_SIZE = 1024 -MODEL = "models/gemini-2.0-flash-live-001" +MODEL = "models/gemini-live-2.5-flash-preview" DEFAULT_MODE = "camera" -client = genai.Client(http_options={"api_version": "v1beta"}) +client = genai.Client( + http_options={"api_version": "v1beta"}, + api_key=os.environ.get("GEMINI_API_KEY") +) + -CONFIG = {"response_modalities": ["AUDIO"]} +CONFIG = types.LiveConnectConfig( + response_modalities=[ + "AUDIO", + ], + media_resolution="MEDIA_RESOLUTION_MEDIUM", + speech_config=types.SpeechConfig( + voice_config=types.VoiceConfig( + prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Zephyr") + ) + ), + context_window_compression=types.ContextWindowCompressionConfig( + trigger_tokens=25600, + sliding_window=types.SlidingWindow(target_tokens=12800), + ), +) pya = pyaudio.PyAudio() @@ -105,7 +117,7 @@ async def send_text(self): ) if text.lower() == "q": break - await self.session.send(input=text or ".", end_of_turn=True) + await self.session.send_client_content(turns={"role": "user", "parts": [{"text": text or "."}]}, turn_complete=True) def _get_frame(self, cap): # Read the frameq @@ -178,7 +190,7 @@ async def get_screen(self): async def send_realtime(self): while True: msg = await self.out_queue.get() - await self.session.send(input=msg) + await self.session.send_realtime_input(media=msg) async def listen_audio(self): mic_info = pya.get_default_input_device_info() From f6231781b43729aed4b3d2f0da7ec5148fdd9420 Mon Sep 17 00:00:00 2001 From: for_the_zero Date: Sat, 4 Oct 2025 17:46:51 +0800 Subject: [PATCH 2/2] Update Get_started_LiveAPI.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- quickstarts/Get_started_LiveAPI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstarts/Get_started_LiveAPI.py b/quickstarts/Get_started_LiveAPI.py index 708e6a62e..b0b5c4adc 100755 --- a/quickstarts/Get_started_LiveAPI.py +++ b/quickstarts/Get_started_LiveAPI.py @@ -73,7 +73,7 @@ client = genai.Client( http_options={"api_version": "v1beta"}, - api_key=os.environ.get("GEMINI_API_KEY") + api_key=os.environ.get("GOOGLE_API_KEY") )