how to integrate eleven labs tts with livekitt?
# ask-ai
b
how to integrate eleven labs tts with livekitt?
t
Thanks for reaching out, Rongrong. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! To help you integrate Eleven Labs TTS with LiveKit, I’ve put together a simple step-by-step guide for you: 1. Installation: First, you’ll want to install the LiveKit plugin for ElevenLabs TTS. You can do this easily using pip:
pip install "livekit-agents[elevenlabs]~=1.2"
Alternatively, if you prefer, you can install it directly from PyPI with:
pip install livekit-plugins-elevenlabs
2. Authentication: Next, you’ll need to get your ElevenLabs API key. You can grab it from ElevenLabs API settings. Once you have it, set it as an environment variable like this:
ELEVEN_API_KEY=<your-api-key>
To make things easier, you might want to save it in a
.env
file. 3. Integration: Now, you can use ElevenLabs TTS inside an
AgentSession
in your LiveKit app. Here’s a quick example to get you started:
Copy code
from livekit.plugins import elevenlabs

session = AgentSession(
    tts=elevenlabs.TTS(
        voice_id="ODq5zmih8GrVes37Dizd",
        model="eleven_multilingual_v2"
    )
    # ... other parameters such as llm, stt, etc.
)
4. Example Implementation: To give you a clearer picture, here’s a basic example of connecting to a room and using ElevenLabs TTS to say a phrase:
Copy code
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()
    options.source = rtc.TrackSource.SOURCE_MICROPHONE

    await job.connect()
    publication = await job.room.local_participant.publish_track(track, options)
    await publication.wait_for_subscription()

    logger.info('Saying "Bonjour, comment allez-vous?"')
    async for output in tts_11labs.synthesize("Bonjour, comment allez-vous?"):
        await source.capture_frame(output.frame)
If you’d like to explore more, including advanced setup options, be sure to check out the ElevenLabs TTS integration guide. And please don’t hesitate to reach out if you have any questions or need a hand—I’m here to help! Sources: ElevenLabs TTS integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/__ini... | Working with plugins | LiveKit Docs