how to enable tts streaming adn llm streaming in a...
# ask-ai
e
how to enable tts streaming adn llm streaming in agents ession pipeline
t
Thanks for reaching out, Guess. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to enable TTS streaming and LLM streaming in an AgentSession pipeline — good news: both stream by default. Here’s what to check and how to ensure real-time behavior. 1) LLM streaming • LLMs in AgentSession emit tokens incrementally by default (e.g., LiveKit inference models and plugin LLMs like
openai.LLM
). • Ensure you consume the LLM as a stream (async iterable). Example pattern:
Copy code
async for chunk in llm_stream:
    yield chunk  # forwarded to downstream nodes
2) TTS streaming • TTS streaming is enabled when the TTS node receives incremental text. If the LLM streams tokens, the
tts_node
will synthesize audio incrementally. • Some TTS plugins offer latency tuning (e.g., ElevenLabs
streaming_latency
) to reduce audio delay. 3) End-to-end pipeline • STT -> LLM -> TTS streams end-to-end by default when the LLM outputs incrementally and you pass those chunks to the TTS node. Example config:
Copy code
session = AgentSession(
  llm="openai/gpt-4.1-mini",
  stt="assemblyai/universal-streaming:en",
  tts="cartesia/sonic-3:…",
)
4) Troubleshooting quick checklist • Confirm your LLM integration returns an async stream (not a single batched string). • Ensure your code forwards chunks to the TTS node as they arrive. • If using a plugin with latency/settings, lower
streaming_latency
or equivalent for faster audio output. If you want, tell me which LLM and TTS plugin you're using and I’ll show the exact code snippet to stream tokens through your AgentSession. Sources: ElevenLabs TTS plugin guide | LiveKit Docs | Large language models (LLM) | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs
e
llm using gemini 2.5 flash and tts cartesia - sonic 3
t
Great — since you're using Gemini 2.5 Flash (Google LLM) and Cartesia Sonic 3, streaming is supported end-to-end. Here’s a concise checklist and minimal example to ensure real-time LLM→TTS streaming in your AgentSession. What to ensure • Use the Google LLM plugin with model "gemini-2.5-flash" — it streams tokens incrementally. • Use the Cartesia TTS plugin with model "sonic-3" — it accepts incremental text and streams audio frames. • Forward LLM tokens as they arrive (async iterable) to the TTS node so audio is synthesized progressively. • Provide your Google API key via env var or
api_key
parameter. Minimal Python example
Copy code
from livekit.agents import AgentSession
from livekit.plugins import google, cartesia

llm = google.LLM(model="gemini-2.5-flash")
tts = cartesia.TTS(model="sonic-3", voice="your_voice_id")

session = AgentSession(llm=llm, tts=tts, stt=None)

# When generating replies, consume streamed chunks and pass to TTS
async for chunk in llm.chat_stream(chat_ctx):     # stream of token chunks
    await tts.synthesize_stream(chunk.delta)      # feed incremental text to TTS
Quick troubleshooting • If audio waits until the end, confirm your LLM code returns an async stream (not a single string). • If playback lags, check Cartesia connection/voice settings; some plugins offer latency tuning. • Ensure
GOOGLE_API_KEY
(or
api_key
) is set for Google plugin. If you want, tell me whether you want the full AgentSession start/room example or a Node.js snippet and I’ll provide it. Sources: Google Gemini LLM plugin guide | LiveKit Docs | Gemini TTS plugin guide | LiveKit Docs | Cartesia TTS plugin guide | LiveKit docs | Agent speech and audio | LiveKit docs