TOOL WIKI · VOICE & REALTIME
Google Gemini Live
Streams audio and other modalities through a stateful live connection.
Jump to a section 10 sections
EXAMPLE USE CASE
Hold a two-way microphone conversation
A spoken support interface needs capture, turn handling, transcription or playback with explicit media formats and a verifiable outcome.
- Input
- 16 kHz mono PCM microphone input and the fixed returns-policy instruction.
- Expected output
- 24 kHz model audio played while the session continues across turns.
- Success check: Microphone frames are sent as 16 kHz mono 16-bit PCM; replies are played as 24 kHz mono 16-bit PCM.
- Try a failure: Interrupt the reply and verify stale audio is cleared before the next turn.
Example scope: Actual capture/network/playback program, not a text-to-WAV substitute; requires your devices and provider configuration.
Official reference · Google Gemini Live
Obtain microphone consent and handle audio devices and interruption.
Realtime voice or multimodal conversations in a Gemini application. Handle session lifecycle, media formats, and reconnect behavior explicitly.
tool callTo 04 · Business toolscontextTo 05 · State + contextmeasureTo 06 · Quality + latencyUse the speech and reasoning services required by the selected architecture.
Resolve the actual actor and resource before executing actions requested during a call.
Keep confirmed business outcomes separate from transient audio buffers.
Result or stopping pointTest noisy audio, overlapping speech, tool timeouts, and reconnection.
Result or stopping point
Realtime voice or multimodal conversations in a Gemini application. Handle session lifecycle, media formats, and reconnect behavior explicitly.
When to consider it
- Realtime voice or multimodal conversations in a Gemini application.
A design decision to make
- Handle session lifecycle, media formats, and reconnect behavior explicitly.
Prerequisites and setup
- Python 3.11+, a microphone, speakers and a Gemini API key/model with Live API access. Use headphones to reduce speaker-to-microphone feedback.
- Install PortAudio through your platform package manager if PyAudio requires it; on macOS: brew install portaudio. The program asks your OS for microphone permission when you run it.
- This 120-second local lab makes provider audio calls when you run it. The website itself does not access your microphone or credentials.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install google-genai pyaudio
export GEMINI_API_KEY="YOUR_KEY"
export GEMINI_LIVE_MODEL="YOUR_ENABLED_LIVE_AUDIO_MODEL"Try a small integration
live_audio.py
import asyncio
import os
import pyaudio
from google import genai
from google.genai import types
async def main():
audio = pyaudio.PyAudio()
mic = speaker = None
queue = asyncio.Queue(maxsize=50)
try:
mic = audio.open(format=pyaudio.paInt16, channels=1, rate=16000,
input=True, frames_per_buffer=1024)
speaker = audio.open(format=pyaudio.paInt16, channels=1, rate=24000, output=True)
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
config = {"response_modalities":["AUDIO"], "system_instruction":
"Be concise. Demo policy: returns accepted within 30 days. "
"Answer only from this policy; never invent order statuses."}
async with client.aio.live.connect(
model=os.environ["GEMINI_LIVE_MODEL"], config=config) as session:
async def send_microphone():
while True:
data = await asyncio.to_thread(mic.read, 1024, exception_on_overflow=False)
await session.send_realtime_input(audio=types.Blob(
data=data, mime_type="audio/pcm;rate=16000"))
async def receive_audio():
while True:
# receive() yields one turn; repeat for the next turn.
async for message in session.receive():
content = message.server_content
if not content:
continue
if content.interrupted:
while not queue.empty():
queue.get_nowait() # Discard stale playback.
for part in (content.model_turn.parts if content.model_turn else []):
if part.inline_data and part.inline_data.data:
await queue.put(part.inline_data.data)
if part.text:
print(part.text)
async def play_audio():
while True:
await asyncio.to_thread(speaker.write, await queue.get())
print("Connected. Ask a returns question; Ctrl+C stops. Lab limit: 120 seconds.")
async with asyncio.timeout(120):
async with asyncio.TaskGroup() as tasks:
tasks.create_task(send_microphone())
tasks.create_task(receive_audio())
tasks.create_task(play_audio())
except TimeoutError:
print("Demo session time limit reached")
finally:
for stream in (mic, speaker):
if stream:
stream.stop_stream()
stream.close()
audio.terminate()
try:
asyncio.run(main())
except KeyboardInterrupt:
print("Stopped")Run and check the result
python live_audio.py
# Say: Can I return an item after twenty days?
# Interrupt with a follow-up, then press Ctrl+C to stop.- Microphone frames are sent as 16 kHz mono 16-bit PCM; replies are played as 24 kHz mono 16-bit PCM.
- The reply should use the supplied 30-day policy. A new spoken turn should produce a new reply without restarting the program.
- Interrupt the model and verify stale queued playback is cleared. Ctrl+C and the time limit must close both audio devices.
Common failures
- Permission/device errors need a working microphone and OS permission; a valid API key does not establish the audio path.
- An unavailable Live model, disconnected WebSocket or unsupported session configuration must surface as an error.
- Headphones and a bounded output queue reduce feedback/backlog; production echo cancellation and reconnect/session-resume are separate work.
Production decisions
- Use an authenticated session backend or supported ephemeral client tokens for browser/mobile clients, with permanent keys on the server.
- Add consent, session limits, redacted observability, real interruption/reconnect tests and tool authorization before customer use.
- Measure real end-of-turn latency and audio quality on target devices. This example has documentation/syntax review; paid provider calls and audio hardware are not executed by site QA.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.