high-printer-10755
11/25/2025, 2:24 PMtall-airline-16756
11/25/2025, 2:25 PMtall-airline-16756
11/25/2025, 2:25 PMexport 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
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 | DeepWikihigh-printer-10755
11/27/2025, 1:27 PMtall-airline-16756
11/27/2025, 1:28 PMpreemptive_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 Docshigh-printer-10755
11/27/2025, 3:08 PMtall-airline-16756
11/27/2025, 3:08 PMstt and tts from your AgentSession. The realtime model will handle audio I/O internally, so external STT/TTS are not invoked.
Examples:
• Python
session = AgentSession(
llm=openai.realtime.RealtimeModel()
)
• Node.js
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 Docshigh-printer-10755
11/27/2025, 3:09 PMtall-airline-16756
11/27/2025, 3:09 PMllm 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.high-printer-10755
11/28/2025, 6:35 AMtall-airline-16756
11/28/2025, 6:36 AMhigh-printer-10755
11/28/2025, 10:20 AMtall-airline-16756
11/28/2025, 10:20 AMhigh-printer-10755
11/28/2025, 10:21 AMtall-airline-16756
11/28/2025, 10:21 AMmodalities=["text"] only changes the response modality to text; it does not change the model ID.
Sources: OpenAI Realtime API plugin guide | LiveKit docshigh-printer-10755
11/28/2025, 10:35 AMtall-airline-16756
11/28/2025, 10:35 AMllm 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
const session = new voice.AgentSession({
llm: openai.realtime.RealtimeModel({ /* keep modalities=["text"] to avoid model TTS/STT */ }),
stt: myExternalSttClient,
tts: myExternalTtsClient,
});
Python
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)?high-printer-10755
11/28/2025, 2:47 PMtall-airline-16756
11/28/2025, 2:48 PMnova-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 docshigh-printer-10755
12/02/2025, 11:42 AMtall-airline-16756
12/02/2025, 11:42 AMtext_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)
tts = aws.TTS(voice="Ruth", language="en-US", text_type="ssml")
Example SSML
<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 Docshigh-printer-10755
12/02/2025, 11:44 AMtts_node) to inject SSML or replace tokens before sending to Polly.tall-airline-16756
12/02/2025, 11:44 AMtts_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)
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)
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?high-printer-10755
12/02/2025, 11:46 AM<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.tall-airline-16756
12/02/2025, 11:47 AMhigh-printer-10755
12/02/2025, 11:52 AMhigh-printer-10755
12/02/2025, 12:07 PM