Documentation
¶
Overview ¶
Package geminilive presents Google's Live API as a Realtime endpoint.
BidiGenerateContent is not a dialect of the Realtime protocol. It has no event type field - messages are discriminated by which top-level key is present - no conversation items, no session updates after the handshake, and it wants 16 kHz audio in while the Realtime wire carries 24 kHz. So this is a translator rather than a profile.
It exists as a translator rather than a second binding because the upstream binding needs exactly four methods from its connection. Meeting those with a package that speaks Gemini on one side and the Realtime protocol on the other keeps one runtime, one mirror, and one set of interaction policies, and leaves the translation independently testable.
Three of Gemini's differences are load-bearing:
- The system instruction can only be set in the opening setup message. So setup is deferred until the caller's first session.update arrives, and anything sent before that is held rather than dropped.
- Transcription arrives incrementally with no completion event. Input text is accumulated and reported when the turn completes, which is the point the Realtime protocol reports it.
- Input audio must be 16 kHz. It is resampled here rather than at the caller, because the caller is speaking a protocol that says 24 kHz.
Index ¶
Constants ¶
const ( // DefaultURL is the Live API WebSocket endpoint. DefaultURL = "wss://generativelanguage.googleapis.com/ws/" + "google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent" // DefaultModel is a Live-capable model. Like every default model in this // project it is a hint: ask the API which models list bidiGenerateContent. DefaultModel = "gemini-2.5-flash-native-audio-latest" // InputSampleRateHz is what the Live API requires of input audio. InputSampleRateHz = uint32(16_000) // OutputSampleRateHz is what it produces, and happens to be what the // Realtime wire carries, so output is passed through unresampled. OutputSampleRateHz = uint32(24_000) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Live connection wearing the Realtime protocol.
func (*Client) Events ¶
func (client *Client) Events() <-chan realtimeclient.Event
Events yields translated Realtime server events.
func (*Client) Send ¶
Send translates one Realtime client event into Live protocol messages.
An event with no Live equivalent is accepted and dropped rather than refused. The caller is speaking a protocol this endpoint does not implement, and failing its ordinary traffic would take down a session over a message that changes nothing - response.cancel being the clear case, since Gemini interrupts on new input rather than on request.
type Config ¶
type Config struct {
// URL is the Live endpoint. Empty selects DefaultURL.
URL string
// APIKey is sent as the key query parameter.
APIKey string
// Model is the Live model. A bare name is prefixed with "models/".
Model string
// Header carries additional request headers.
Header http.Header
// CallerSampleRateHz is the rate the caller sends audio at. Empty selects
// the Realtime wire's 24 kHz.
CallerSampleRateHz uint32
// DialTimeout bounds connection establishment.
DialTimeout time.Duration
// WriteTimeout bounds one send on an established connection. Zero selects
// the shipped default; a negative value removes the bound.
//
// The dial was bounded and the sends that follow it were not. The context
// reaching them comes from the session and has no deadline, so a stalled
// socket blocks a send that carries a caller's audio - and this client is
// the foreground voice, so what stops is the conversation.
WriteTimeout time.Duration
// ReadLimit bounds one inbound message.
ReadLimit int64
// HTTPClient dials the WebSocket.
HTTPClient *http.Client
}
Config configures one translated connection.