cool-optician-76909
12/18/2025, 6:11 AMtall-airline-16756
12/18/2025, 6:11 AMcool-optician-76909
12/18/2025, 6:11 AMtall-airline-16756
12/18/2025, 6:12 AMcartesia/sonic-3).
Quick config examples 1) Gemini 2.0 Flash (native realtime):
session = AgentSession(
llm=google.realtime.RealtimeModel(
model="gemini-2.0-flash",
voice="Puck",
temperature=0.8,
),
)
2) Text-only with separate fast TTS:
session = AgentSession(
llm=google.realtime.RealtimeModel(modalities=["TEXT"]),
tts="cartesia/sonic-3"
)
Best practices to reduce response delay
• Network proximity: Co-locate your LiveKit agents and SIP gateway close to Google services and use LiveKit Cloud’s global mesh to reduce RTT.
• Turn-detection: Use Gemini’s built-in turn detection/VAD rather than a separate external detector to avoid extra processing and round trips.
• Target latency goals: aim for TTFT < 500 ms, TTFB < 300 ms, and end-to-end < ~1.5 s as practical benchmarks.
• Optimize audio pipeline: minimize buffering, use low-latency audio codecs/settings on the SIP gateway, and keep frame sizes small.
• Parallelize TTS: when using text-only + TTS, stream TTS audio as soon as tokens are available rather than waiting for full response generation.
• Monitor metrics: track TTFT, TTFB, and end-to-end latency in production and correlate spikes with network, codec, or model changes.
If you’d like, I can:
• Help evaluate whether switching to Gemini 2.0 Flash or text-only + TTS fits your current architecture.
• Suggest specific SIP/audio settings to reduce buffering and codec-related delay.
Which would you like to do next?
Sources: Gemini Live API plugin | LiveKit docs | examples/frontdesk | livekit/livekit_composite | DeepWikicool-optician-76909
12/18/2025, 6:14 AMtall-airline-16756
12/18/2025, 6:14 AMcool-optician-76909
12/18/2025, 6:17 AMtall-airline-16756
12/18/2025, 6:17 AMcartesia/sonic-3). This lets you stream TTS audio as soon as tokens are available.
Practical best practices (priority-ordered)
1. Network / deployment
◦ Co-locate LiveKit, SIP gateway/PBX, and the Google realtime endpoint in the same region to minimize RTT.
◦ Use LiveKit Cloud’s global mesh or colocated infrastructure when possible.
1. Model / turn detection
◦ Prefer Gemini’s built-in turn detection/VAD to avoid extra round trips from external detectors.
◦ Use gemini-2.0-flash for lower TTFT; switch to text-only + TTS only if you need tighter TTS control.
1. Audio pipeline & codecs
◦ Use low-latency codecs and small frame sizes (e.g., Opus with 20ms frames) and minimize codec transcoding between SIP and LiveKit.
◦ Reduce capture/playout buffering and keep SIP jitter buffer conservative but not excessive.
1. Streaming & parallelism
◦ Stream partial responses and start TTS generation as soon as first tokens arrive; don’t wait for full response.
◦ Parallelize STT → model request → TTS where possible (e.g., start model generation while ASR finalization still in flight if partial ASR is usable).
1. Tuning buffering and timeouts
◦ Reduce internal audio buffering in LiveKit pipeline and SIP gateway. Avoid large batch windows for voice chunking.
◦ Tune VAD thresholds so voice segments are sent promptly without trimming needed speech.
1. Prompt and response design
◦ Keep prompts and system context minimal for latency-sensitive calls; move long context to short retrieval or summarization flows.
◦ Favor concise instructions that let the model emit tokens sooner (avoid heavy, multi-step reasoning inline).
1. Tooling and intermediate processing
◦ Minimize or offload synchronous post-processing (heavy NLP, sentiment, profanity checks) to async tasks unless required before TTS.
◦ If external tools are required, pipeline them asynchronously and stream intermediate outputs when safe.
1. Monitoring & targets
◦ Instrument and monitor TTFT, TTFB, and end-to-end latency. Target TTFT < 500 ms, TTFB < 300 ms, and end-to-end < ~1.5 s where practical.
◦ Correlate spikes with network, codec transcodes, or model selection.
If you want, I can:
• Recommend specific SIP codec/frame settings for your gateway.
• Walk through how to switch to gemini-2.0-flash or text-only + cartesia/sonic-3 TTS in your current AgentSession config.
Which of those would help most right now?cool-optician-76909
12/18/2025, 6:19 AMgemini-2.0-flash or text-only + cartesia/sonic-3 TTS in your current AgentSession config.
Which of those would help most right now?tall-airline-16756
12/18/2025, 6:19 AMgemini-2.0-flash or text-only + cartesia/sonic-3 TTS. Below are concise, ready-to-use examples and the minimal steps to apply each option.
Option A — Quick switch to gemini-2.0-flash (lower-latency, simple)
• Use when you want easier setup and lower model latency without separate TTS auth.
Python
from livekit.agents import AgentSession
session = AgentSession(
stt="assemblyai/universal-streaming", # or your STT
llm="google/gemini-2.0-flash",
tts="cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
# optional: vad=True, turn_detection="builtin"
)
Node.js / TypeScript
import { AgentSession } from "@livekit/agents";
const session = new AgentSession({
stt: "assemblyai/universal-streaming",
llm: "google/gemini-2.0-flash",
tts: "cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
});
Option B — Text-only Gemini Live API + cartesia/sonic-3 TTS (best control, lowest perceived latency)
• Use when you need maximum latency control and can provide Google API key.
1) Install plugin and set API key:
• Install Google plugin in your Agents environment (if not already).
• Set env var: export GOOGLE_API_KEY=your_api_key_here
2) Config examples
Python
from livekit.agents import AgentSession
from livekit.plugins import google
session = AgentSession(
llm=google.realtime.RealtimeModel(
model="gemini-2.0-flash",
modalities=["text"], # disables built-in TTS/audio
api_key="your_api_key_here", # or rely on GOOGLE_API_KEY env var
),
tts="cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
# optional: use_tts_aligned_transcript=True, preemptive_generation=True
)
Node.js / TypeScript
import * as google from "@livekit/agents-plugin-google";
import { AgentSession } from "@livekit/agents";
const session = new AgentSession({
llm: new google.realtime.RealtimeModel({
model: "gemini-2.0-flash",
modalities: ["text"],
apiKey: process.env.GOOGLE_API_KEY,
}),
tts: "cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
});
Practical tips when using text-only + Cartesia TTS
• Stream TTS as soon as partial text tokens are available; don’t wait for full response.
• Set use_tts_aligned_transcript=True if you need better frontend sync of words ↔️ audio.
• Consider preemptive_generation=True to start generating speculative tokens before turn end (careful with hallucination risk).
Which should you try first?
• If you want the fastest path with minimal changes: switch to gemini-2.0-flash (Option A).
• If you need the absolute lowest perceived latency and fine control over voice output: use text-only + cartesia/sonic-3 (Option B).
Tell me which option you want to roll out and whether you want a patch/PR-ready snippet for your repo (Python or Node).
Sources: HIPAA Eligible Products and Services | LiveKit | Google Gemini LLM | LiveKit Docs | Gemini Live API plugin | LiveKit docs | OpenAI Realtime API plugin guide | LiveKit docs | Text and transcriptions | LiveKit docscool-optician-76909
12/18/2025, 6:21 AMtall-airline-16756
12/18/2025, 6:22 AMkey field. In your pasted code it's voicename — ensure the actual string is voice_name.
• Error handling: wrap DB operations in try/catch so failures log and don’t leave partial state.
• Relations: you set synthesizerProvider on models/configs. Ensure the entity relation is configured to accept the provider object (not just provider id).
• Consistent identifiers: include an explicit unique identifier or slug for the model if your app relies on it (e.g., modelKey: "gemini-2.5-flash-tts").
• Active flags & defaults: confirm isActive and active flags match your app semantics (enabled vs. visible).
Optional improvements
• Create the model with metadata like displayName or capabilities if your UI needs it.
• Use a transaction to ensure atomic seed execution.
• Add created_at/updated_at if your entities use timestamps.
If you want, I can:
• Provide a patched seed file with idempotent checks, try/catch, and a transaction (Python or TypeScript).
Which would you like?cool-optician-76909
12/18/2025, 6:23 AMtall-airline-16756
12/18/2025, 6:23 AMcool-optician-76909
12/18/2025, 6:24 AMtall-airline-16756
12/18/2025, 6:24 AMcool-optician-76909
12/18/2025, 6:30 AMtall-airline-16756
12/18/2025, 6:31 AMproactivity=True and `enable_affective_dialog=True`: these features add internal processing and decision-making time.
• `_gemini_tools=[GoogleSearch(), GoogleMaps()]`: calling tools introduces external API calls and waiting for results.
• thinking_config.include_thoughts is off (good), but any extended thinking or internal reasoning modes can increase TTFT/TTFB.
• Native audio + tool usage makes the pipeline end-to-end synchronous (ASR → LLM audio gen → TTS) which compounds delays.
Immediate, high-impact fixes (apply these first)
1. Switch model to gemini-2.0-flash for lower model latency:
◦ llm.model="gemini-2.0-flash"
1. Disable proactivity, affective dialog, and tool calls for latency-sensitive calls:
◦ proactivity=False, enable_affective_dialog=False, remove _gemini_tools unless essential.
1. If you need absolute lowest perceived latency, use text-only mode + fast external TTS (Cartesia Sonic-3):
◦ run Gemini with modalities=["text"] and set tts="cartesia/sonic-3:...".
◦ Stream text tokens to TTS as soon as partial tokens arrive (don’t wait for full response).
1. Prefer built-in VAD/turn detection and small audio frames:
◦ Keep turn_detection="builtin" or equivalent so you avoid extra round trips.
◦ Use Opus 20ms frames (or similarly small frames) and minimize capture/playout buffering.
Secondary tuning (after immediate fixes)
• Disable or avoid synchronous tool usage; if required, call tools asynchronously and stream partial replies.
• Set preemptive_generation=True only after testing (can help but may increase hallucination risk).
• Reduce internal buffering and jitter buffer sizes in SIP gateway; avoid large batching windows.
• Monitor TTFT and TTFB and correlate with model/tool calls to confirm improvements.
Suggested config example (minimal changes)
• Quick low-effort change (lower latency, same pipeline):
llm = google.realtime.RealtimeModel(
model="gemini-2.0-flash",
voice="Leda",
proactivity=False,
enable_affective_dialog=False,
# remove _gemini_tools
)
• Best-performance change (text-only + Cartesia TTS):
llm = google.realtime.RealtimeModel(
model="gemini-2.0-flash",
modalities=["text"], # disables built-in audio gen
api_key="YOUR_GOOGLE_API_KEY",
)
# then set session.tts = "cartesia/sonic-3:..."
If you want, I can:
• Produce a patch of your AgentSession with the minimal changes applied, or
• Review your full AgentSession + SIP codec/jitter settings and a short timestamped trace to point to the exact bottleneck (TTFT vs TTS streaming).
Which would you prefer?cool-optician-76909
12/18/2025, 7:07 AMtall-airline-16756
12/18/2025, 7:07 AMcool-optician-76909
12/18/2025, 7:09 AMtall-airline-16756
12/18/2025, 7:10 AMgemini-2.5-flash-native-audio-* previews). You can enable those via LiveKit Inference or the Google plugin.
If you want, I can give exact copy‑paste Python code to enable:
• gemini-2.5-flash via LiveKit Inference (no Google key), or
• a Gemini realtime model (native audio or text-only) via the Google plugin (requires GOOGLE_API_KEY),
and include the best low-latency flags and recommended changes for SIP. Which of the two do you want me to provide code for?
Sources: Gemini Live API plugin | LiveKit docs | Google Gemini LLM plugin guide | LiveKit Docs | Google Gemini LLM | LiveKit Docs | Agents Framework | livekit/livekit_composite | DeepWiki | HIPAA Eligible Products and Services | LiveKit