how can i implement streaming for 11labs 2.5 flash...
# ask-ai
c
how can i implement streaming for 11labs 2.5 flash model in livekit inference tts
t
Thanks for reaching out, Relency. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you get started with streaming for the ElevenLabs Flash 2.5 model in LiveKit inference TTS! Here's a simple code snippet you can use:
Copy code
from livekit.agents import TTS

tts = TTS(
    model="elevenlabs/eleven_flash_v2_5",
    voice="your_voice_id"  # You can choose a voice ID from the ElevenLabs voice library
)

stream = tts.stream()
This model is quite versatile and supports a variety of languages, including English, Japanese, Chinese, German, Hindi, French, Korean, Portuguese, Italian, Spanish, Indonesian, Dutch, Turkish, and more. Just a quick note on pricing: the service costs $150 per 1M characters through LiveKit Inference. If you want to explore different voices, feel free to check out the ElevenLabs voice library to find the perfect voice ID for your project. Sources: ElevenLabs TTS plugin guide | LiveKit Docs | Text-to-speech (TTS) models | LiveKit Docs | Build voice, video, and physical AI | LiveKit
c
but we're using inference.tts()
t
I'd be happy to help you get started with the ElevenLabs Flash 2.5 model using
inference.tts()
. Here's a simple example to guide you:
Copy code
from livekit.agents.inference import tts as inference_tts

tts = inference_tts.TTS(
    model="elevenlabs/eleven_flash_v2_5",
    voice="voice_id",  # Be sure to replace this with the voice ID you want to use
    language="en",
    api_key="your_livekit_api_key",
    api_secret="your_livekit_api_secret"
)
Just a quick note: please make sure to replace
voice_id
with a valid ElevenLabs voice ID. Currently, custom or cloned voices aren't supported in LiveKit Inference. If you want to customize things a bit more, you can add options like
inactivity_timeout
and
apply_text_normalization
through
extra_kwargs
. Here's how that looks:
Copy code
tts = inference_tts.TTS(
    model="elevenlabs/eleven_flash_v2_5",
    voice="voice_id",
    language="en",
    api_key="your_livekit_api_key",
    api_secret="your_livekit_api_secret",
    extra_kwargs={"inactivity_timeout": 120, "apply_text_normalization": "on"}
)
If anything feels unclear or if you have any more questions, please don’t hesitate to reach out. I’m here to help! Sources: docs/index.yaml | plugins/elevenlabs/src/tts.ts | ElevenLabs TTS | LiveKit Docs | livekit-agents/livekit/agents/inference/tts.py | Build voice, video, and physical AI | LiveKit
c
how about streaming with tts based on llm output
t
I'd love to help you implement streaming TTS based on LLM output in LiveKit! You can achieve this smoothly by using the Agent Framework, which processes and vocalizes LLM responses bit by bit. Here's a simple example workflow to guide you:
Copy code
tts = cartesia.TTS()
source = rtc.AudioSource(tts.sample_rate, tts.num_channels)
track = rtc.LocalAudioTrack.create_audio_track("agent-mic", source)
await job.room.local_participant.publish_track(track)

stream = tts.stream()
text = "hello from Cartesia. I hope you are having a great day."
words = text.split()
for i in range(0, len(words), 2):
    chunk = " ".join(words[i : i + 2])
    stream.push_text(chunk + " ")

stream.flush()
stream.end_input()
This example gently simulates LLM streaming by breaking the text into smaller chunks and pushing them to the TTS stream. Plus, if you'd like, you can customize the LLM output before sending it to TTS by using the
before_tts_cb
callback to clean up or transform the text exactly how you want. Please feel free to reach out if you'd like me to walk you through any part of this or if you have specific configurations in mind. I'm here to help! Sources: Tool definition and use | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | README.md | Pipeline nodes and hooks | LiveKit Docs | chain-of-thought-tts/README.mdoc
c
does llm output directly get streamed to the tts model or does wait for the entire response, i'm using inference and cant find documentation on this. Do i have to create separate node functions to do this?
t
In LiveKit inference, the LLM output streams directly to the TTS model without waiting for the entire response, which helps things flow smoothly. The
llm_node
sends output chunks asynchronously as they’re generated, and the
tts_node
processes these chunks bit by bit. This way, if your TTS model supports streaming, you get real-time synthesis. If your TTS model doesn’t support streaming natively, no worries! LiveKit uses a sentence tokenizer to split the text into smaller segments for incremental synthesis. You don’t need to create separate node functions for this since the streaming behavior is already built into the agent pipeline architecture. Please feel free to reach out if you’d like me to clarify anything further or help you with your setup—I’m here for you! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Pipeline nodes and hooks | LiveKit Docs | Docs::Agents | Modifying LLM output before TTS | LiveKit Docs