Cartesia
Cartesia provides a VoxEngine client for connecting a call or media unit to the Cartesia Agents WebSocket API.
Use Cartesia.createAgentsClient(...) to create an AgentsClient for the current scenario.
Related guides
Contents
- Usage: required module import and basic flow.
- Factory functions: create the Cartesia Agents client.
- Methods: start, DTMF, and custom agent messages.
- Events: WebSocket media bridge events.
- AgentsEvents: Cartesia Agents event names and payload fields.
Usage
Add the module before using the namespace:
Create the client, bridge media, and listen for Cartesia Agents events.
Factory functions
createAgentsClient
Creates a Cartesia.AgentsClient instance.
Parameters
Returns
createRealtimeTTSPlayer
Creates a new Cartesia.RealtimeTTSPlayer instance with the specified text (TTS is used to play the text). You can attach media streams later via the Cartesia.RealtimeTTSPlayer.sendMediaTo or VoxEngine.sendMediaBetween methods.
Parameters
Returns
AgentsClient
Methods
addEventListener
Adds a handler for the specified Cartesia.AgentsEvents or Cartesia.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 Cartesia WebSocket media buffer.
Parameters
Returns
close
Closes the Cartesia connection (over WebSocket) or connection attempt.
Parameters
This method does not accept parameters.
Returns
custom
Sends custom metadata to the agent. https://docs.cartesia.ai/line/integrations/web-calls#custom-event
Parameters
Returns
dtmf
Sends DTMF (dual-tone multi-frequency) tones. https://docs.cartesia.ai/line/integrations/web-calls#dtmf-event
Parameters
Returns
id
Returns the AgentsClient id.
Parameters
This method does not accept parameters.
Returns
removeEventListener
Removes a handler for the specified Cartesia.AgentsEvents or Cartesia.Events event.
Parameters
Returns
sendMediaTo
Starts sending media from the Cartesia (via WebSocket) to the media unit. Cartesia works in real time.
Parameters
Returns
start
Initializes the audio stream configuration. https://docs.cartesia.ai/line/integrations/web-calls#start-event
Parameters
Returns
stopMediaTo
Stops sending media from the Cartesia (via WebSocket) to the media unit.
Parameters
Returns
webSocketId
Returns the Cartesia WebSocket id.
Parameters
This method does not accept parameters.
Returns
Events
These events describe audio received through the Cartesia WebSocket media bridge.
WebSocketMediaStarted
Triggered when the audio stream sent by a third party through a Cartesia 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 Cartesia WebSocket (1 second of silence).
Event constant: Events.WebSocketMediaEnded
Payload
AgentsEvents
These events mirror server messages from the Cartesia Agents WebSocket API. The data field contains the provider event payload.
Unknown
The unknown event.
Event constant: AgentsEvents.Unknown
Payload
HTTPResponse
The HTTP response event.
Event constant: AgentsEvents.HTTPResponse
Payload
ACK
Server acknowledgment of the start event, confirming stream configuration. https://docs.cartesia.ai/line/integrations/web-calls#ack-event
Event constant: AgentsEvents.ACK
Payload
Clear
Indicates the agent wants to clear/interrupt the current audio stream. https://docs.cartesia.ai/line/integrations/web-calls#clear-event
Event constant: AgentsEvents.Clear
Payload
DTMF
Server sends DTMF tones from the agent. https://docs.cartesia.ai/line/integrations/web-calls#dtmf-event-2
Event constant: AgentsEvents.DTMF
Payload
Custom
Server sends custom metadata from the agent. https://docs.cartesia.ai/line/integrations/web-calls#custom-event-2
Event constant: AgentsEvents.Custom
Payload
WebSocketError
The WebSocket error response event.
Event constant: AgentsEvents.WebSocketError
Payload
ConnectorInformation
Contains information about connector.
Event constant: AgentsEvents.ConnectorInformation
Payload