Eleven Labs Integration
A guide on how to integrate and use Eleven Labs TTS in your realtime Voice Bot using Outspeed.
Ensure you have completed the Quick Start - Simple Voice Bot guide before proceeding with this guide.
Integrating Eleven Labs TTS into Your Voice Bot
In this guide, we will enhance your basic Voice Bot by integrating Eleven Labs TTS (Text-to-Speech) to convert text responses into natural-sounding speech. This integration provides a more engaging and interactive user experience.
- The full code is available here.
Prerequisites
Before integrating Eleven Labs TTS, ensure you have the following:
- API Keys:
- Eleven Labs - For text-to-speech. Sign up and navigate to your API keys to obtain your API key.
- Additionally, ensure you have API keys for Deepgram and Groq as outlined in the Quick Start guide.
Setup Environment Variables
Create a .env
file in the same directory as voice_bot.py
and add your API keys:
Understanding the ElevenLabsTTS Plugin
The ElevenLabsTTS
plugin is a powerful component that enables text-to-speech synthesis using the Eleven Labs API. Let’s explore its key features and functionality:
Initialization
The plugin is initialized with several parameters:
api_key
: Your Eleven Labs API key (can be set via environment variableELEVEN_LABS_API_KEY
)voice_id
: The ID of the voice to use for synthesismodel
: The TTS model to use (default is “eleven_turbo_v2_5”)output_format
: The audio output format ('pcm_16000'
,'pcm_24000'
,'mp3_22050_32'
,'mp3_44100_128'
)optimize_streaming_latency
: Latency optimization level for streamingstream
: Whether to stream the audio output (default isTrue
)
Key Features
- Asynchronous Operation: The plugin operates asynchronously, efficiently managing text input and audio output streams.
- Streaming Support: It supports streaming audio output, allowing for low-latency speech synthesis.
- Interrupt Handling: The plugin can handle interruptions (e.g., when the user starts speaking) by cancelling ongoing TTS generation and clearing queues.
- Flexible Output Formats: Supports multiple audio output formats to suit different application needs.
- Tracing and Logging: Includes tracing and logging functionality for monitoring performance and debugging.
Usage
To use the ElevenLabsTTS plugin in your Voice Bot:
-
Initialize the plugin in your
setup
method: -
In your
run
method, connect the text input to the TTS node:
This integration allows your Voice Bot to convert text responses into natural-sounding speech, enhancing the interactive experience for users.
Updating voice_bot.py
to Use Eleven Labs TTS
Ensure your voice_bot.py
includes the Eleven Labs TTS integration as shown below:
This setup ensures that your Voice Bot utilizes the Eleven Labs TTS service for generating audio responses based on the processed text input.
Was this page helpful?