createGeminiLiveAdapter owns browser microphone streaming, PCM audio playback, input/output
metering, local turn detection, interruptions, and cleanup. Your app owns the official Google GenAI
client and the short-lived Live API token.
The examples use gemini-3.1-flash-live-preview, the current low-latency voice-first Live model,
with the Kore voice.
The simple setup
The browser provides one connect callback that returns an official Google Live session. orb-ui
then owns microphone capture, PCM streaming and playback, local turn detection, state mapping,
audio metering, interruptions, and cleanup. The callback exists so @google/genai remains an
optional, app-owned dependency instead of increasing orb-ui’s runtime bundle for every user.
Install the Google GenAI SDK
Mint an ephemeral token on your server
Keep the standard Gemini API key on your server. Lock the one-use token to the model and audio
configuration your client will use.
Add authentication and rate limiting appropriate for your app before exposing a token endpoint.
Create the adapter
The server configuration disables automatic VAD because the adapter uses client-side activity
detection by default. It sends explicit activityStart and activityEnd markers from its local
speech detector, which is the tested, deterministic voice-turn path. If your Gemini session uses
server-side VAD instead, keep automatic activity detection enabled and set
activityDetection: 'server' in the adapter.
Audio behavior
The adapter resamples browser microphone input to 16 kHz PCM and sends it with
sendRealtimeInput. Gemini’s base64 PCM output is decoded, queued, and played at the sample rate
declared by each response chunk. An interruption stops all queued audio immediately.
State and volume mapping
- token/session connection ->
connecting
- active microphone/user speech ->
listening
- end of detected user speech or model text work ->
thinking
- queued native audio ->
speaking when the user is not currently speaking
- interruption,
waitingForInput, or completed playback -> listening
- Live session failure ->
error
- explicit stop or closed connection ->
idle
inputVolume follows the local microphone. outputVolume follows the PCM playback analyser.
Directional calibration
During user interruption, microphone activity keeps the UI in listening while buffered response
chunks arrive and the server stops playback. Those chunks do not switch the animation back to
speaking. Gemini output defaults are calibrated from live native-audio responses independently
of microphone input; input and output do not share amplitude anchors.
Gemini Live ships with separate microphone and PCM playback profiles. Use partial directional
overrides only for a materially different audio path, and use a getter when a generated profile
must update during an active session:
The provider playground captures silence, quiet, normal, and energetic speech and generates the
amplitude anchors automatically. See volume calibration for the
shared contract and runner workflow.
Token handling
Gemini recommends ephemeral tokens for direct browser-to-Live connections. Do not ship a standard
Gemini API key in the browser. The token and connection must both use the v1alpha API while
ephemeral Live authentication remains on that endpoint.
Last modified on September 8, 2026