geminilive

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 Dial

func Dial(ctx context.Context, config Config) (*Client, error)

Dial opens the connection and starts translating.

func (*Client) Close

func (client *Client) Close() error

Close ends the connection.

func (*Client) Err

func (client *Client) Err() error

Err reports why reading stopped, or nil for a clean close.

func (*Client) Events

func (client *Client) Events() <-chan realtimeclient.Event

Events yields translated Realtime server events.

func (*Client) Send

func (client *Client) Send(ctx context.Context, value any) error

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.

func (*Client) Wait

func (client *Client) Wait()

Wait blocks until reading has finished.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL