Python SDK
Conversational AI SDK: deploy customized, interactive voice agents in minutes.
Also see the Conversational AI overview
Installation
Install the elevenlabs
Python package in your project:
If you want to use the default implementation of audio input/output you will also need the pyaudio
extra:
The pyaudio
package installation might require additional system dependencies.
See PyAudio package README for more information.
On Debian-based systems you can install the dependencies with:
Usage
In this example we will create a simple script that runs a conversation with the ElevenLabs Conversational AI agent. You can find the full code in the ElevenLabs examples repository.
First import the necessary dependencies:
Next load the agent ID and API key from environment variables:
The API key is only required for non-public agents that have authentication enabled. You don’t have to set it for public agents and the code will work fine without it.
Then create the ElevenLabs
client instance:
Now we initialize the Conversation
instance:
We are using the DefaultAudioInterface
which uses the default system audio input/output devices for the conversation.
You can also implement your own audio interface by subclassing elevenlabs.conversational_ai.conversation.AudioInterface
.
Now we can start the conversation:
To get a clean shutdown when the user presses Ctrl+C
we can add a signal handler which will call end_session()
:
And lastly we wait for the conversation to end and print out the conversation ID (which can be used for reviewing the conversation history and debugging):
All that is left is to run the script and start talking to the agent:
Was this page helpful?