Gemini
Voice agent client for Google Gemini Live API real-time voice scenarios.
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.
Related guides
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:
Create the client, bridge media, and listen for Live API events.
Factory functions
createLiveAPIClient
Creates a Gemini.LiveAPIClient instance.
Parameters
Returns
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.
Parameters
Returns
clearMediaBuffer
Clears the LiveAPI WebSocket media buffer.
Parameters
Returns
close
Closes the LiveAPI connection (over WebSocket) or connection attempt.
Parameters
This method does not accept parameters.
Returns
id
Returns the LiveAPIClient id.
Parameters
This method does not accept parameters.
Returns
removeEventListener
Removes a handler for the specified Gemini.LiveAPIEvents or Gemini.Events event.
Parameters
Returns
sendClientContent
Transmits a LiveClientContent over the established connection. https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendClientContent
Parameters
Returns
sendMediaTo
Starts sending media from the LiveAPI (via WebSocket) to the media unit. LiveAPI works in real time.
Parameters
Returns
sendRealtimeInput
Transmits a LiveClientRealtimeInput over the established connection. https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendRealtimeInput
Parameters
Returns
sendToolResponse
Transmits a LiveClientToolResponse over the established connection. https://pkg.go.dev/google.golang.org/genai@v1.57.0#Session.SendToolResponse
Parameters
Returns
stopMediaTo
Stops sending media from the LiveAPI (via WebSocket) to the media unit.
Parameters
Returns
webSocketId
Returns the LiveAPI WebSocket id.
Parameters
This method does not accept parameters.
Returns
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
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
LiveAPIEvents
These events mirror server messages from the Gemini Live API. The data field contains the provider event payload.
Unknown
The unknown event.
Event constant: LiveAPIEvents.Unknown
Payload
ServerContent
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
ToolCall
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
ToolCallCancellation
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
ConnectorInformation
Contains information about connector.
Event constant: LiveAPIEvents.ConnectorInformation
Payload