React SDK
Conversational AI SDK: deploy customized, interactive voice agents in minutes.
Also see the Conversational AI overview
Installation
Install the package in your project through package manager.
Usage
useConversation
React hook for managing websocket connection and audio usage for ElevenLabs Conversational AI.
Initialize conversation
First, initialize the Conversation instance.
Note that Conversational AI requires microphone access. Consider explaining and allowing access in your apps UI before the Conversation kicks off.
Options
The Conversation can be initialized with certain options. Those are all optional.
- onConnect - handler called when the conversation websocket connection is established.
- onDisconnect - handler called when the conversation websocket connection is ended.
- onMessage - handler called when a new message is received. These can be tentative or final transcriptions of user voice, replies produced by LLM, or debug message when a debug option is enabled.
- onError - handler called when a error is encountered.
Methods
startConversation
startConversation
method kick off the websocket connection and starts using microphone to communicate with the ElevenLabs Conversational AI agent.
The method accepts options object, with the url
or agentId
option being required.
Agent ID can be acquired through ElevenLabs UI and is always necessary.
For the public agents, define agentId
- no signed link generation necessary.
In case the conversation requires authorization, use the REST API to generate signed links. Use the signed link as a url
parameter.
startSession
returns promise resolving to conversationId
. The value is a globally unique conversation ID you can use to identify separate conversations.
endSession
A method to manually end the conversation. The method will end the conversation and disconnect from websocket.
setVolume
A method to set the output volume of the conversation. Accepts object with volume field between 0 and 1.
status
A React state containing the current status of the conversation.
isSpeaking
A React state containing the information of whether the agent is currently speaking. This is helpful for indicating the mode in your UI.