witty-kangaroo-6889
09/16/2025, 12:30 AMtall-airline-16756
09/16/2025, 12:30 AMtall-airline-16756
09/16/2025, 12:30 AMpip install "livekit-agents[elevenlabs]~=1.2"
If you prefer the standalone package, you can use this instead:
pip install livekit-plugins-elevenlabs
Authentication
Next, you’ll need an ElevenLabs API key. Once you have it, set it as an environment variable in your .env file like this:
ELEVEN_API_KEY=<your-api-key>
The plugin will pick up this key automatically, making things easier for you.
Example Code
Here’s a simple example to get you started with standalone usage:
import asyncio
from dotenv import load_dotenv
from livekit import rtc
from livekit.agents import JobContext, cli
from livekit.plugins import elevenlabs
load_dotenv()
async def entrypoint(job: JobContext):
tts_11labs = elevenlabs.TTS(
voice_id="ODq5zmih8GrVes37Dizd",
model="eleven_multilingual_v2"
)
source = rtc.AudioSource(tts_11labs.sample_rate, tts_11labs.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("agent-mic", source)
options = rtc.TrackPublishOptions(source=rtc.TrackSource.SOURCE_MICROPHONE)
await job.connect()
publication = await job.room.local_participant.publish_track(track, options)
await publication.wait_for_subscription()
async for output in tts_11labs.synthesize("Bonjour, comment allez-vous?"):
await source.capture_frame(output.frame)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Dynamic Language Switching
One of the cool features is that you can switch languages on the fly during runtime! Just use this command:
tts_11labs.update_options(language="es") # Switch to Spanish
If you want to dive deeper or check out more details, feel free to visit the ElevenLabs TTS plugin reference. I’m sure you’ll find it really helpful!
Sources: ElevenLabs TTS integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-elevenlabs/README.md | pipeline-tts/elevenlabs_change_language.pywitty-kangaroo-6889
09/16/2025, 12:46 AMtall-airline-16756
09/16/2025, 12:46 AMwitty-kangaroo-6889
09/16/2025, 12:47 AMtall-airline-16756
09/16/2025, 12:48 AMwitty-kangaroo-6889
09/16/2025, 12:48 AMtall-airline-16756
09/16/2025, 12:49 AMpip install "livekit-agents[elevenlabs]~=1.2"
Then, add your ElevenLabs API key to a .env file like this:
ELEVEN_API_KEY=<your-api-key>
2. Voice and Model Selection
Next, you’ll want to configure a voice that sounds warm and empathetic. Here’s an example using the TTS class:
from livekit.plugins import elevenlabs
tts_instance = elevenlabs.TTS(
voice_id="EXAVITQu4vr4xnSDxMaL", # "Bella", known for warm tone
model="eleven_multilingual_v2",
voice_settings=elevenlabs.VoiceSettings(
stability=0.65,
similarity_boost=0.6,
style=0.4,
use_speaker_boost=True,
speed=0.95 # Slightly slower for empathy
),
language="en"
)
The voice_id "EXAVITQu4vr4xnSDxMaL" corresponds to "Bella," a voice that’s recognized for its warm and clear qualities—perfect for your use case.
3. Programmatically List and Select Voices
If you want to explore and pick the best voice, you can use list_voices() like this:
async def select_empathetic_voice():
tts = elevenlabs.TTS()
voices = await tts.list_voices()
candidate_voices = [v for v in voices if "bella" in v.name.lower() or "jessica" in v.name.lower()]
return candidate_voices
4. Integrate with AgentSession and SIP
Once you have your voice ready, you can integrate it into a telephony-capable AgentSession like so:
session = AgentSession(
tts=tts_instance,
stt=deepgram.STT(), # Example STT
llm=openai.LLM(),
vad=silero.VAD.load(),
allow_interruptions=False
)
5. Enhance Empathy Through LLM Instructions
To make sure your agent responds with genuine empathy, you can provide clear instructions to the language model:
instructions = """
You are a compassionate and professional debt collection agent.
Acknowledge the user’s financial stress, offer flexible payment options,
and always maintain a respectful and understanding tone.
Avoid aggressive language or pressure.
"""
6. Test and Evaluate Voice Output
• A/B Test Voices: Try different `voice_id`s in test calls to see which one feels most empathetic.
• Use SSML for Pronunciation: Enable enable_ssml_parsing=True to ensure financial terms are pronounced correctly.
• Enable Transcription Alignment: Set use_tts_aligned_transcript=True in AgentSession for synchronized transcription.
If you have any questions or need help with any part of this setup, please don’t hesitate to reach out. I’m here to support you!
Sources: ElevenLabs TTS integration guide | LiveKit Docs | ElevenLabs integration guide | LiveKit Docs | examples/warm-transfer/warm_transfer.py | plugins/elevenlabs/src/tts.ts