true while a model response is in flight (generation started and not yet done).
Distinct from IsAudioPlaying: generation runs ahead of playback.
Hosts use this to gate interim narration so it never interrupts a reply.
ProtectedattachAttaches (replacing + closing any previous) the USER-microphone meter. null detaches.
ProtectedattachAttaches (replacing + closing any previous) the AGENT-output meter. null detaches.
has no explicit cancel frame — the client OWNS the audio plane, so cancelling means: flush the local playout queue (GeminiPcmPlayback) so speech stops immediately, mark the in-flight turn inactive, and drain queued sends (a queued tool result or context note takes the floor next — tool-result delivery is never dropped by a cancel). Server-side, the next client content sent naturally interrupts any residual generation per the Live API contract. The interrupted turn's accumulated transcript is kept — the provider's trailing frames finalize what WAS spoken. No-op when nothing is active.
ProtectedcloseReleases both meters — every driver calls this from its disconnect/teardown path.
Opens the client-direct Gemini Live session: creates the playout engine, connects with
the ephemeral token + the server-built SessionConfig ({ model, config } — the same
values the server LOCKED into the token, so tampering is ignored by the API), then wires
the mic-capture worklet. Reports 'listening' once audio is flowing.
ProtectedconnectCreation seam for the Gemini Live session. Production constructs a GoogleGenAI client
with the ephemeral token as the API key on the v1alpha API version (the only
version that accepts auth_tokens), then opens live.connect with the server-built
model + config. Unit tests override this to return an in-memory fake.
ProtectedcreateCreation seam for the mic-capture pipeline. Production delegates to the shared
createPcmMicCapture (a 16 kHz AudioContext, inline-Blob capture worklet, and a
zero-gain tail; each worklet block is PCM16-encoded and handed to onPcmChunk as base64).
Unit tests override this with a no-op fake (and may capture onPcmChunk to simulate mic
frames).
ProtectedcreateCreation seam for the playout engine. Production returns GeminiPcmPlayback.
Tears down the session, mic capture, mic tracks, and playout engine, resets the response
state machine, and emits a final 'closed' (unless already 'error'). Safe to call
more than once.
ProtectedemitProtectedemitEmits a true barge-in interruption to the registered handler (if any).
ProtectedemitEmits the model/avatar's remote video stream to the registered handler (video drivers only).
ProtectedemitEmits a state change to the registered handler (if any).
ProtectedemitEmits a tool-call request to the registered handler (if any).
ProtectedemitEmits a transcript event to the registered handler (if any).
ProtectedemitEmits a usage update (token deltas for a completed response/turn) to the registered handler (if any).
The session's current audible activity, or null when this driver attached no
meters at all (hosts then keep their turn-state-driven visuals). Sampled by hosts
per animation frame — implementations are cheap, allocation-light reads of an
AnalyserNode; no per-call provider traffic.
OptionalGetReturns the AGENT's remote-audio MediaStream when this driver owns a tappable
remote-audio plane (e.g. a WebRTC peer-connection driver routes the model's audio track
here), or null otherwise. Hosts use it to MIX the agent's voice into a browser-side
recording alongside the mic; a null return (the default, and what every non-WebRTC
driver gives) degrades gracefully to mic-only capture.
Optional capability: the method itself is optional — call sites must use
client.GetRemoteMediaStream?.() ?? null. Drivers that can't expose a remote stream
simply don't implement it (or return null).
Registers the (single) error handler. Receives both fatal transport errors (which are
also followed by an 'error' state change) and non-fatal provider error frames.
Registers the (single) interruption handler.
True barge-in only: fires ONLY when USER INPUT CUT OFF ACTIVE MODEL OUTPUT — a model response in flight or audio audibly playing when the user took the floor. A user simply taking their normal turn while the model is idle is NOT an interruption, and drivers must not report it as one (e.g. a raw "speech started" frame must be gated on whether a response is actually active or audio is playing).
On interruption, drivers must also flush locally-owned playback and report
IsAudioPlaying === false promptly (driver obligation #3). Hosts typically
use this hook to abort in-flight delegated work so a stale result is never narrated
into a conversation that has moved on.
OptionalOnOptional capability: registers a handler invoked when the agent's remote-audio stream
becomes available — immediately if it has already landed, otherwise when the WebRTC track
arrives (typically AFTER Connect resolves). Lets a host attach the agent voice to a
recording that began before the track landed. Call as client.OnRemoteMediaStream?.(cb);
drivers without a remote stream simply don't implement it.
Registers the (single) remote-VIDEO handler — the model/avatar's video track for a VIDEO session (a talking-head the host renders, e.g. as the agent's tile). Invoked once the provider publishes its video track.
Optional capability: audio-only drivers (the default) never emit — registering is always safe, but hosts must not assume a video track arrives. Video-capable drivers (BaseRealtimeModel.SupportsVideo) call emitRemoteVideo when the track is live.
Invoked with the remote video MediaStream when it becomes available.
Registers the (single) state-change handler. States may be re-emitted (e.g. repeated
'listening' on successive barge-ins); hosts should treat emissions as idempotent.
Registers the (single) tool-call handler. The host executes the tool and calls SendToolResult with the outcome.
Registers the (single) transcript handler. Receives interim deltas (IsFinal: false)
and final turn transcripts (IsFinal: true) for both roles, tagged with their
RealtimeClientTranscript.Kind.
Registers the (single) usage handler.
Emissions carry token deltas for the response/turn that just completed (see
RealtimeClientUsage — deltas preferred; cumulative-only providers must convert
in the driver). Hosts accumulate and relay/persist on their own cadence (e.g. the voice
session service debounces a RelayRealtimeUsage mutation onto the co-agent prompt run).
Optional capability: drivers whose provider exposes no usage telemetry simply never emit — registering a handler is always safe, but hosts must not assume emissions arrive. See RealtimeClientUsage for per-driver availability.
Triggers ONE short spoken update. Gemini has no per-response instructions (OpenAI's
response.create.instructions), so this is EMULATED: the instructions ride as a
realtime-text user turn (sendRealtimeInput({ text }) — the path that triggers
generation on native-audio models, where mid-call sendClientContent is inert), and
the resulting turn is stamped Kind: 'narration' at send time (reset on
turnComplete) — mirroring the OpenAI driver's narration semantics. Queued behind any
in-flight turn so it can never interrupt a pending reply.
Injects background context as a user turn with turnComplete: false — appended to the
conversation WITHOUT starting generation, so the model draws on it the next time it
speaks. Gemini Live turns have no system role, so the user role carries it (the host owns
prefixing policy). Queued while a turn is in flight because ANY client content interrupts
in-flight generation on Gemini (a divergence from the OpenAI driver, which can inject
items mid-response safely).
SIDE EFFECT: turnComplete: false leaves the client content turn OPEN — the server
holds generation until a turnComplete: true commit arrives. openClientTurn
tracks this so SendToolResult can commit the turn and unblock the spoken reply.
Injects typed text as a realtime-text user turn (sendRealtimeInput({ text }) —
Gemini's "respond now" trigger on every Live model generation, including native-audio
models that ignore mid-call sendClientContent). No-op when the session is not open.
SendText implies barge-in (base-contract rule): an active spoken response is cancelled via CancelActiveResponse first — playback flushed, turn marked inactive, queued sends drained — so the typed turn takes the floor immediately. If a drained queued send (e.g. a pending tool result) starts a new turn, the text queues behind it, preserving the tool-result delivery invariant. On the wire, sending the user turn itself interrupts any residual server-side generation (Gemini Live's any-client-content-interrupts contract), so no explicit cancel frame exists or is needed.
Feeds an executed tool's result back via sendToolResponse, supplying the function name
cached from the originating tool call (Gemini requires it; the contract only carries the
callID). Sent immediately when idle — Gemini speaks the result as its next turn —
otherwise queued until the in-flight turn (e.g. a progress narration) completes.
If context notes left a client content turn OPEN (turnComplete: false), the tool
response is followed by an empty-turn commit (sendClientContent({ turnComplete: true }))
— without it the server keeps waiting for more client input and NEVER starts the spoken
reply (observed live as the model staying silent after a delegated agent's result).
Mutes / unmutes by toggling the mic tracks' enabled flag: the capture pipeline stays
up and streams SILENCE while muted (chosen over gating the worklet send so the provider's
VAD sees a continuous stream and the un-mute is glitch-free — same policy as the OpenAI
client driver).
Google Gemini implementation of BaseRealtimeClient: a browser-direct Gemini Live websocket session authenticated with the server-minted ephemeral auth token (
v1alphaauth_tokensmechanism — the token is passed as the SDKapiKey).Registered with the ClassFactory under the key
'gemini'— theProviderstring the server'sGeminiRealtimedriver stamps on itsClientRealtimeSessionConfig— so hosts resolve it without referencing this class directly.Owns ALL Gemini wire concerns (the behavioral twin of OpenAIRealtimeClient, adapted to Gemini's client-owned audio plane — there is no WebRTC here):
AudioWorklet(createMicCapture seam) and streamed withsendRealtimeInput.inputTranscription→ User deltas/finals,outputTranscription→ Assistant deltas/finals (accumulated like the OpenAI driver),toolCall.functionCalls→ OnToolCall (callID→name cached for SendToolResult),interrupted→ playback flush +'listening',turnComplete→ busy cleared + queued sends flushed,usageMetadata→ OnUsage (per-turn prompt/response token deltas — see handleUsageMetadata).response.createdframe, soIsBusyis set EAGERLY when this client triggers a response (text / narration / tool result) and on the first model output of a turn (audio part or output-transcription delta); cleared onturnComplete, and on atoolCallframe (the model has yielded the floor pending the tool result — so a slowturnCompletecan never deadlock the queued result).sendClientContentinterrupts in-flight Gemini generation (per the Live API contract), so text / narration / context-note / tool-result sends issued while a turn is in flight are queued and flushed in order onturnComplete(the flush stops at the first send that starts a new response).turnComplete: falseclient content, which tells the Live API MORE INPUT IS COMING — the server holds ALL generation (including the normally-automatic continuation after a tool response) until aturnComplete: truecommit. SendToolResult therefore followssendToolResponsewith an empty-turn commit whenever a note left the turn open, so the model speaks the result immediately (the behavioral equivalent of the OpenAI driver's explicitresponse.create).sendRealtimeInput({ text })— the Live API's documented in-conversation text path. Native-audio Live models treatsendClientContentas initial-history seeding only: a mid-callturnComplete: trueclient turn appends to history WITHOUT starting generation (the model stays silent until the user's next spoken turn), while realtime text triggers an immediate response on every model generation. Context notes stay onsendClientContent(turnComplete: false) — the silent history-append is exactly the contract they want.'narration'at send time (sends ARE the turn triggers on Gemini, unlike OpenAI whereresponse.createdconfirms) and reset to'normal'when the turn completes.