Gemini

Voice agent client for Google Gemini Live API real-time voice scenarios.

View as Markdown

Gemini provides a VoxEngine client for connecting a call or media unit to the Google Gemini Live API over WebSocket.

Use Gemini.createLiveAPIClient(...) to create a LiveAPIClient for the current scenario.

Contents

  • Usage: required module import and basic flow.
  • Factory functions: create the Gemini Live client.
  • Methods: media, response, and connection control methods.
  • Events: WebSocket media bridge events.
  • LiveAPIEvents: Gemini Live API event names and payload fields.

Usage

Add the module before using the namespace:

1require(Modules.Gemini);

Create the client, bridge media, and listen for Live API events.

Factory functions

createLiveAPIClient

Creates a Gemini.LiveAPIClient instance.

1createLiveAPIClient(parameters: LiveAPIClientParameters): Promise<LiveAPIClient>

Parameters

ParameterTypeReq.Description
parametersLiveAPIClientParameters

Returns

TypeDescription
Promise<LiveAPIClient>Resolves to the Gemini.LiveAPIClient instance.

LiveAPIClient

Methods

addEventListener

Adds a handler for the specified Gemini.LiveAPIEvents or Gemini.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.

1addEventListener(event: Events | LiveAPIEvents | string, callback: (event: object) => any): void

Parameters

ParameterTypeReq.Description
eventEvents | LiveAPIEvents | stringEvent constant or event name to subscribe to.
callback(event: object) => anyFunction called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

clearMediaBuffer

Clears the LiveAPI WebSocket media buffer.

1clearMediaBuffer(parameters?: ClearMediaBufferParameters): void

Parameters

ParameterTypeReq.Description
parametersClearMediaBufferParameters

Returns

TypeDescription
voidDoes not return a value.

close

Closes the LiveAPI connection (over WebSocket) or connection attempt.

1close(): void

Parameters

This method does not accept parameters.

Returns

TypeDescription
voidDoes not return a value.

id

Returns the LiveAPIClient id.

1id(): string

Parameters

This method does not accept parameters.

Returns

TypeDescription
stringThe requested string value.

removeEventListener

Removes a handler for the specified Gemini.LiveAPIEvents or Gemini.Events event.

1removeEventListener(event: Events | LiveAPIEvents | string, callback?: (event: object) => any): void

Parameters

ParameterTypeReq.Description
eventEvents | LiveAPIEvents | stringEvent constant or event name to subscribe to.
callback(event: object) => anyFunction called when the event is emitted.

Returns

TypeDescription
voidDoes not return a value.

sendClientContent

Transmits a LiveClientContent over the established connection. https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendClientContent

1sendClientContent(input: Object): void

Parameters

ParameterTypeReq.Description
inputObject

Returns

TypeDescription
voidDoes not return a value.

sendMediaTo

Starts sending media from the LiveAPI (via WebSocket) to the media unit. LiveAPI works in real time.

1sendMediaTo(mediaUnit: VoxMediaUnit, parameters?: SendMediaParameters): void

Parameters

ParameterTypeReq.Description
mediaUnitVoxMediaUnit
parametersSendMediaParameters

Returns

TypeDescription
voidDoes not return a value.

sendRealtimeInput

Transmits a LiveClientRealtimeInput over the established connection. https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendRealtimeInput

1sendRealtimeInput(input: Object): void

Parameters

ParameterTypeReq.Description
inputObject

Returns

TypeDescription
voidDoes not return a value.

sendToolResponse

Transmits a LiveClientToolResponse over the established connection. https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendToolResponse

1sendToolResponse(input: Object): void

Parameters

ParameterTypeReq.Description
inputObject

Returns

TypeDescription
voidDoes not return a value.

stopMediaTo

Stops sending media from the LiveAPI (via WebSocket) to the media unit.

1stopMediaTo(mediaUnit: VoxMediaUnit): void

Parameters

ParameterTypeReq.Description
mediaUnitVoxMediaUnit

Returns

TypeDescription
voidDoes not return a value.

webSocketId

Returns the LiveAPI WebSocket id.

1webSocketId(): string

Parameters

This method does not accept parameters.

Returns

TypeDescription
stringThe requested string value.

Events

These events describe audio received through the Gemini WebSocket media bridge.

WebSocketMediaStarted

Triggered when the audio stream sent by a third party through a Gemini WebSocket is started playing.

Event constant: Events.WebSocketMediaStarted

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
tagstringSpecial tag to name audio streams sent over one WebSocket connection. With it, one can send 2 audios to 2 different media units at the same time.
encodingstringAudio encoding formats.
customParameters{ [key: string]: string }Custom parameters.

WebSocketMediaEnded

Triggers after the end of the audio stream sent by a third party through a Gemini WebSocket (1 second of silence).

Event constant: Events.WebSocketMediaEnded

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
tagstringSpecial tag to name audio streams sent over one WebSocket connection. With it, one can send 2 audios to 2 different media units at the same time.
mediaInfoWebSocketMediaInfoInformation about the audio stream that can be obtained after the stream stops or pauses (1 second of silence).

LiveAPIEvents

These events mirror server messages from the Gemini Live API. The data field contains the provider event payload.

The unknown event.

Event constant: LiveAPIEvents.Unknown

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
dataObjectThe event’s data.

Content generated by the model in response to client messages. https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerContent

Event constant: LiveAPIEvents.ServerContent

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
dataObjectThe event’s data.

Request for the client to execute the function_calls and return the responses with the matching ids. https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerToolCall

Event constant: LiveAPIEvents.ToolCall

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
dataObjectThe event’s data.

Notification for the client that a previously issued ToolCallMessage with the specified ids should have been not executed and should be cancelled. https://pkg.go.dev/google.golang.org/genai@v1.57.0#LiveServerToolCallCancellation

Event constant: LiveAPIEvents.ToolCallCancellation

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
dataObjectThe event’s data.

Contains information about connector.

Event constant: LiveAPIEvents.ConnectorInformation

Payload

FieldTypeReq.Description
clientLiveAPIClientThe Gemini.LiveAPIClient instance.
dataObjectThe event’s data.