Skip to content
Skip to article
Docs Gemini Live audio
View as Markdown

Gemini Live audio

Add a Google Gemini provider key from Google AI Studio. In the router’s Routing Chain, select that key and a Live model such as gemini-3.8-live. Use Custom… if the model is missing from the picker. Your backend connects to DodoRouter with its router API key. DodoRouter supplies the Google key to the Gemini Developer API. Router URL and key · Google AI Studio’s Live API overview.

Send speech and save the reply

Install google-genai with python -m pip install google-genai. Set DODO_ROUTER_URL to the HTTPS router root, such as https://api.dodorouter.com/r/my-agent, and set DODO_ROUTER_API_KEY. This server-side Python example sends a spoken question from input.wav and saves Gemini’s answer to reply.wav.

import asyncio
import os
import wave

from google import genai
from google.genai import types

async def main():
    client = genai.Client(
        vertexai=False,
        api_key=os.environ["DODO_ROUTER_API_KEY"],
        http_options={
            "base_url": os.environ["DODO_ROUTER_URL"].rstrip("/"),
            "api_version": "v1beta",
        },
    )
    config = {
        "response_modalities": ["AUDIO"],
        "realtime_input_config": {"automatic_activity_detection": {"disabled": True}},
    }
    async with client.aio.live.connect(model="default", config=config) as session:
        with wave.open("input.wav", "rb") as clip:
            if (clip.getnchannels(), clip.getsampwidth(), clip.getframerate()) != (1, 2, 16000):
                raise ValueError("Supply a mono, 16-bit PCM WAV file at 16 kHz")
            await session.send_realtime_input(activity_start=types.ActivityStart())
            while chunk := clip.readframes(1600):
                audio = types.Blob(data=chunk, mime_type="audio/pcm;rate=16000")
                await session.send_realtime_input(audio=audio)
            await session.send_realtime_input(activity_end=types.ActivityEnd())

        with wave.open("reply.wav", "wb") as reply:
            reply.setparams((1, 2, 24000, 0, "NONE", "PCM"))
            async for message in session.receive():
                if message.data:
                    reply.writeframesraw(message.data)

asyncio.run(main())

For microphone conversations, send PCM chunks as you capture them and play the returned mono, 24 kHz PCM as it arrives. Gemini’s default voice activity detection recognizes pauses and interruptions. The example uses manual activity boundaries so the entire file counts as one turn. Google’s server-side SDK tutorial · Audio and turn detection.

WebSocket clients

Open wss://api.dodorouter.com/r/{router_slug}/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent. A server-side client can send its router key in Authorization: Bearer … or x-goog-api-key. The route also accepts the Google JavaScript SDK’s key query parameter. Keep the router key on your server and redact that parameter in reverse-proxy access logs.

Send setup as the first JSON message. DodoRouter selects the model from the routing step and preserves the session options, including voice, transcription and tools. Wait for setupComplete before sending realtimeInput. Audio chunks travel as base64 inside JSON. Use serverContent.interrupted to clear pending playback when the user interrupts. Gemini Live protocol reference.

Routing and logs

During setup, DodoRouter tries Google Live steps in order until Google sends setupComplete. That step owns the conversation. To resume after a disconnect, enable Gemini’s sessionResumption option, save the latest resumable handle and send it in the next setup on the same router. The original model and provider key must still be configured. Reuse X-Session-Id across connections to keep the turns together in Logs.

Gemini’s turnComplete creates a Realtime log with the serving model, session ID, terminal status and reported usageMetadata. The log retains token counts and omits media and transcripts. A disconnect before the turn finishes can leave that turn without a usage record. In MCP, filter list_logs by provider: "google" and session_id. Audio pricing · Agent access.