Can I prewarm the TTS component?
# ask-ai
h
Can I prewarm the TTS component?
t
Thanks for reaching out, Sara. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes — you can prewarm the TTS component to reduce latency. Prewarming is done by loading the TTS model into the worker's shared state during initialization and reusing it for sessions. Examples: 1) Node.js
Copy code
export default defineAgent({
  prewarm: async (proc: JobProcess) => {
    proc.userData.tts = await cartesia.TTS.load(); // preload TTS
  },
  entry: async (ctx: JobContext) => {
    const tts = ctx.proc.userData.tts!;
    const session = new voice.AgentSession({ tts /*, stt, llm, vad */ });
    // ...
  },
});
2) Python
Copy code
def prewarm(proc: agents.JobProcess):
    proc.userdata["tts"] = cartesia.TTS.load()  # preload TTS

@server.rtc_session()
async def my_agent(ctx: agents.JobContext):
    tts = ctx.proc.userdata["tts"]
    session = AgentSession(tts=tts /*, stt, llm, vad */)
    # ...
Would you like a version tailored to your runtime (Node/Python) or help adding this into your existing agent code? Sources: Silero VAD plugin | LiveKit docs | Agent server options | LiveKit docs | Example Applications & Templates | livekit/livekit_composite | DeepWiki
h
Other than prewarm, preemptive_generation=True, are there any ways i can lower latency for all of these 3 components: stt/llm/tts
t
You're asking for ways beyond prewarm and
preemptive_generation=True
to reduce latency for STT, LLM, and TTS — here are targeted, actionable options you can apply across those three components. STT • Use low-latency streaming providers (Deepgram, Google Cloud, AssemblyAI) rather than batch APIs. • Send smaller audio frames (e.g., 20ms) to reduce real-time responsiveness. • Tune VAD/endpointing: lower
silence_duration_ms
(≈300–500ms) or use LiveKit’s MultilingualModel turn detector for faster, more accurate endpointing. • colocate the worker near the STT provider (same cloud region). LLM • Choose faster models or “mini”/realtime variants (e.g., lower-latency OpenAI/Google/Gemini realtime models). • Use realtime LLM APIs that accept audio or stream tokens to avoid a separate STT→LLM serialization step. • Lower generation work: reduce
temperature
,
reasoning_effort
, max tokens, and prefer shorter prompts/templates. • Prewarm and reuse model connections or clients; keep connections alive to avoid auth/handshake overhead. • Run workers in regions close to the LLM endpoint. TTS • Use instant/streaming modes (provider-specific: Hume/Rime instant modes, ElevenLabs
streaming_latency=1
). • Preload TTS models/instances (prewarm) and reuse the instance across sessions. • Adjust synthesis params: increase
speed_alpha
, reduce stability/quality settings if acceptable. • Use SSML and smaller synthesis chunks (synthesize partial segments) to start playback earlier. • Colocate worker near the TTS provider. Infrastructure & Observability (applies to all three) • Colocate agent workers in the same cloud region as STT/LLM/TTS providers to reduce RTT. • Avoid burstable CPU instances (t3/t4); use fixed-performance instances (
c5
,
m5
,
c6i
) to prevent throttling. • Measure per-component latency via metrics: STT
transcription_delay
, LLM
ttft
, TTS `ttfb`; identify the dominant contributor and optimize that first. • Parallelize where possible (start TTS generation as soon as partial LLM output is available). Practical combination • Prewarm +
preemptive_generation
+ colocated workers + streaming STT + realtime-capable LLM + streaming/instant TTS yields the biggest end-to-end gains. Would you like recommendations tuned to your stack (Node vs Python), current providers, or help identifying which component is causing most of your latency? Sources: examples/bank-ivr | livekit/livekit_composite | DeepWiki | How can I reduce latency in voice agents using STT, TTS and LLM? | Observability data hooks | LiveKit docs | Hume TTS plugin guide | LiveKit Docs | Rime TTS plugin guide | LiveKit Docs
h
and can the tts and stt components be disabled from a realtime model, so we can use it only for its latency?
t
You're asking if STT and TTS can be disabled when using a realtime model so you can use it only for its low latency — yes. • Use a realtime LLM and omit
stt
and
tts
from your
AgentSession
. The realtime model will handle audio I/O internally, so external STT/TTS are not invoked. Examples: • Python
Copy code
session = AgentSession(
  llm=openai.realtime.RealtimeModel()
)
• Node.js
Copy code
const session = new voice.AgentSession({
  llm: openai.realtime.RealtimeModel.withAzure({ /*...*/ })
});
Notes: • The realtime model provides low-latency end-to-end speech, but its internal transcription/endpointing behavior may differ from dedicated STT/VAD solutions. • If you need live captions or custom turn-detection, you can add an STT or turn detector separately (at the cost of added latency and complexity). Would you like a code snippet tailored to your current agent (Node or Python) or to a specific realtime provider? Sources: Realtime model plugins | LiveKit Docs
h
I meant: can the stt and tts abilities of the llm be disabled, so we can use it only for its latency, and we can use other tts and stt providers
t
Yes — you can stop the realtime model from handling STT/TTS and use external STT/TTS providers instead, but with caveats. What to do • Configure your AgentSession to provide only the
llm
realtime model for low-latency token generation, and supply your external
stt
and/or
tts
components in the session instead of relying on the model’s built-in audio processing. ◦ Example (Node): create an AgentSession with
llm: realtimeModel
and set
stt
and/or
tts
to your provider clients. ◦ Example (Python): same pattern — pass
llm=<realtime model>
, and pass `stt=`/`tts=` to external providers. Caveats and important notes • Realtime models are designed as end-to-end audio pipelines; disabling their internal STT/TTS means you may lose some integrated behaviors (internal endpointing, audio format handling, or the model’s optimized audio path). • You must ensure audio format/encoding and timing match the realtime model’s expectations if you route audio separately. • If you need both low-latency audio I/O and advanced external STT/TTS features, a common approach is: ◦ Use the realtime LLM purely for fast token streaming (omit model TTS/STT). ◦ Plug in external STT for live transcription and external TTS for synthesis, and coordinate turn detection/VAD to avoid doubled processing. • Adding external STT/TTS can reintroduce latency; measure STT
transcription_delay
, LLM
ttft
, and TTS
ttfb
to find bottlenecks. If you’d like, tell me: • Which realtime provider (OpenAI, Azure, Gemini) and whether you use Node or Python — I’ll give a concise code example showing how to wire external STT/TTS while using the realtime model for low-latency LLM output.
h
What is the fastest TTS supported by LiveKit
t
The fastest TTS options supported by LiveKit are (best to worst for low latency/streaming): • Inworld (LiveKit Inference) — fast, real-time streaming synthesis. • Groq (LiveKit Inference) — low-latency streaming TTS. • Cartesia Sonic‑Turbo (LiveKit Inference) — optimized for speed and streaming. • Rime and ElevenLabs — support streaming/instant modes when configured for low latency. Use streaming/instant mode, colocate your agent near the provider/LiveKit edge, and enable prewarming to get the lowest end-to-end TTS latency. Would you like a quick example for wiring one of these providers into your Node or Python agent? Sources: Groq and LiveKit | LiveKit Docs | Cartesia TTS | LiveKit docs | Text-to-speech (TTS) models | LiveKit Docs | ElevenLabs TTS | LiveKit Docs | How can I reduce latency in voice agents using STT, TTS and LLM?
h
Recommend me the best realtime model for livekit
t
For most LiveKit realtime voice use cases I recommend OpenAI Realtime (GPT‑4o/GPT‑4o‑mini family) as the best starting point. Why OpenAI Realtime • Ultra low end-to-end latency (~300ms) with token streaming and built-in audio I/O. • Mature WebSocket/Realtime integration and features for interruption handling and synchronized audio. • Good balance of latency, conversational quality, and ecosystem support (used for ChatGPT Advanced Voice). Alternatives to consider • Google Gemini Live — best if you need strong multilingual/native-audio behavior and advanced turn-taking. • Amazon Nova Sonic (Bedrock) — best if you need AWS-native deployment, compliance, and Bedrock integration. • Vendor TTS-focused options (Inworld, Groq, Cartesia Sonic‑Turbo) — pair with a realtime LLM if you need ultra-fast synthesized audio. How to choose • Prioritize OpenAI Realtime for lowest latency + best out-of-the-box conversational behavior. • Choose Gemini Live for multilingual/native-audio needs. • Choose Nova Sonic for AWS/enterprise requirements. If you tell me your primary priorities (lowest latency, multilingual, AWS compliance, or best voice quality) and whether you use Node or Python, I’ll give a concise example and wiring advice for that provider. Sources: OpenAI and LiveKit partner to turn Advanced Voice into an API
h
what is the default model when using it like this llm=openai.realtime.RealtimeModel(modalities=["text"])
t
The default model is "gpt-realtime". Setting
modalities=["text"]
only changes the response modality to text; it does not change the model ID. Sources: OpenAI Realtime API plugin guide | LiveKit docs
h
Can i use a realtime model but with separate stt and tts
t
Yes — you can use a realtime LLM while routing STT and TTS to external providers. Configure your AgentSession with the realtime model for
llm
and pass your external
stt
and/or
tts
implementations; omit the model's built-in audio handling. Key points: • The realtime model will be used only for token generation; your external STT/TTS handle recognition and synthesis. • Ensure audio formats, sample rates, and encoding match what the realtime model and providers expect. • You may lose some integrated behaviors (the model’s internal endpointing, interruption handling, or optimized audio path). Coordinate VAD/turn-detection to avoid duplicated endpointing. • External STT/TTS can reintroduce latency; measure STT
transcription_delay
, LLM
ttft
, and TTS
ttfb
to find bottlenecks. Concise examples: Node.js
Copy code
const session = new voice.AgentSession({
  llm: openai.realtime.RealtimeModel({ /* keep modalities=["text"] to avoid model TTS/STT */ }),
  stt: myExternalSttClient,
  tts: myExternalTtsClient,
});
Python
Copy code
session = AgentSession(
  llm=openai.realtime.RealtimeModel(modalities=["text"]),
  stt=my_external_stt,
  tts=my_external_tts,
)
Would you like a tailored snippet for your provider stack (which realtime provider, STT, TTS, and Node vs Python)?
h
best stt
t
For most use cases in LiveKit, Deepgram Nova-3 is the best STT choice. Why: • Low-latency streaming optimized for real-time conversations. • Strong accuracy in noisy environments and good multilingual support (
nova-3:multi
). • First-class integration via LiveKit Inference (no external key management if using LiveKit Cloud). Alternatives: • AssemblyAI Universal Streaming — excellent streaming accuracy and endpointing for English-heavy apps. • Cartesia Ink Whisper — wide language coverage (130+) if you need global language support. If you tell me your priorities (lowest latency, best accuracy in noise, multilingual, or no-external-keys) and whether you use Node or Python, I’ll give a concise setup example and recommended model config. Sources: Introducing LiveKit Inference: A unified model interface for voice AI | AssemblyAI plugin guide | LiveKit Docs | Cartesia STT | LiveKit Docs | Deepgram STT | LiveKit docs | Deepgram STT plugin guide | LiveKit docs
h
What is the recommended approach on customising pronunciation with Polly?
t
Use SSML with Amazon Polly and set
text_type="ssml"
in your Polly TTS config. Key techniques •
<phoneme alphabet="ipa" ph="...">word</phoneme>
— phonetic pronunciation (IPA or X-SAMPA). •
<say-as interpret-as="acronym|date|number|characters|...">
— force interpretation. •
<break time="100ms"/>
— control pauses/timing. • Lexicons — upload a Polly lexicon to AWS and reference it for reusable pronunciation rules. • Preprocess text (e.g., in a
tts_node
) to inject SSML or replace tokens before sending to Polly. Example config (conceptual)
Copy code
tts = aws.TTS(voice="Ruth", language="en-US", text_type="ssml")
Example SSML
Copy code
<speak>
  Please say <say-as interpret-as="acronym">NASA</say-as>.
  The API is <phoneme alphabet="ipa" ph="ˈeɪ.piːˈaɪ">API</phoneme>.
  <break time="300ms"/>
  Thank you.
</speak>
Would you like a ready-to-drop Node or Python snippet that injects SSML or references a Polly lexicon? Sources: Amazon Polly TTS plugin guide | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docs
h
What do you mean by: Preprocess text (e.g., in a
tts_node
) to inject SSML or replace tokens before sending to Polly.
t
"Preprocess text in a `tts_node`" means intercepting and transforming the outgoing text just before it’s handed to the TTS provider (Polly), so you can inject SSML, replace tokens, apply pronunciation rules, or split long text into chunks. This happens inside the agent pipeline where you control how responses are turned into speech. What the
tts_node
does • Receives the plain text output from your LLM or dialog logic. • Lets you modify that text (insert SSML tags, substitute words, apply lexicon keys, add pauses). • Returns the transformed text to the TTS component, which sends it to Polly with
text_type="ssml"
. Why use it • Central place to enforce consistent pronunciation rules (e.g., expand abbreviations, add phonemes). • Avoids changing your prompts or LLM output directly. • Enables dynamic behavior (per-user lexicons, voice-specific tweaks, conditional SSML). Simple transformations you might do • Replace "HTTP" ->
<say-as interpret-as="characters">HTTP</say-as>
• Replace "ACME Corp" ->
<phoneme alphabet="ipa" ph="ˈækmi">ACME</phoneme>
• Wrap entire output in
<speak>...</speak>
and add
<break>
where needed • Insert SSML only for words on a per-request blacklist/whitelist Concise examples Node.js (conceptual)
Copy code
function ttsNodeTransform(text: string, meta: any) {
  // simple token replacement
  text = text.replace(/\bHTTP\b/g, '<say-as interpret-as="characters">HTTP</say-as>');
  // phoneme injection for a product name
  text = text.replace(/ACME Corp/g, '<phoneme alphabet="ipa" ph="ˈækmi">ACME Corp</phoneme>');
  // ensure SSML root
  return `<speak>${text}</speak>`;
}

// usage when calling TTS
const ssml = ttsNodeTransform(llmOutput, { userId });
polly.synthesize({ Text: ssml, TextType: "ssml", VoiceId: "Ruth" });
Python (conceptual)
Copy code
def tts_node_transform(text: str, meta: dict) -> str:
    text = re.sub(r'\bHTTP\b', '<say-as interpret-as="characters">HTTP</say-as>', text)
    text = text.replace('ACME Corp', '<phoneme alphabet="ipa" ph="ˈækmi">ACME Corp</phoneme>')
    return f"<speak>{text}</speak>"

ssml = tts_node_transform(llm_output, {"user_id": user_id})
polly.synthesize_speech(Text=ssml, TextType="ssml", VoiceId="Ruth")
Practical tips • Ensure Polly config uses
text_type="ssml"
. • Escape or validate user-supplied content to avoid malformed SSML. • Keep transformations deterministic and test pronunciation for edge cases. • Use lexicons for reusable pronunciation rules and only inject phonemes for edge cases. • For very long responses, split into chunks and stream/synthesize progressively to reduce perceived latency. Want a ready-to-drop
tts_node
snippet for your agent (Node or Python) that injects SSML and supports a lexicon lookup?
h
explain this in detail, end to end Key techniques •
<phoneme alphabet="ipa" ph="...">word</phoneme>
— phonetic pronunciation (IPA or X-SAMPA). •
<say-as interpret-as="acronym|date|number|characters|...">
— force interpretation. •
<break time="100ms"/>
— control pauses/timing. • Lexicons — upload a Polly lexicon to AWS and reference it for reusable pronunciation rules. • Preprocess text (e.g., in a
tts_node
) to inject SSML or replace tokens before sending to Polly.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
h
How would the end-to-end pipeline look like using all these key techniques
?