modern-winter-66316
12/04/2025, 9:51 PMtall-airline-16756
12/04/2025, 9:51 PMtall-airline-16756
12/04/2025, 9:51 PMRealtimeModel class and can be used inside an AgentSession, for example:
from livekit.plugins import openai
session = AgentSession(
llm=openai.realtime.RealtimeModel()
)
• Notes: real-time models give low-latency, expressive speech and emotional context, but may have delayed transcription and limited script-based speech control. You can combine real-time models with separate TTS instances for finer control.
Would you like guidance for a specific provider (OpenAI, Azure, Gemini, Nova Sonic, or Ultravox) or sample code for Node.js vs Python?
Sources: Realtime model plugins | LiveKit Docs | Models | LiveKit Docsmodern-winter-66316
12/04/2025, 9:52 PMtall-airline-16756
12/04/2025, 9:52 PMgemini-2.5-flash-native-audio-preview-09-2025 (current supported Gemini Live model)
◦ Fallback: gemini-2.0-flash-exp
• Voices:
◦ Default voice: Puck
◦ Additional voices: Gemini Live can use Google Cloud Text-to-Speech voices via the voice_name mapping — you can pick any supported Google Cloud TTS voice listed here: https://cloud.google.com/text-to-speech/docs/voices
Example usage:
llm = google.realtime.RealtimeModel(
model="gemini-2.5-flash-native-audio-preview-09-2025",
voice="Puck"
)
Do you want a list of specific Google Cloud TTS voice names to try, or a Node.js example?
Sources: Gemini Live API plugin | LiveKit docs | Gemini TTS plugin guide | LiveKit Docsmodern-winter-66316
12/04/2025, 9:58 PM"Good morning! May I see your passport and booking confirmation, please?"Common Phrases: • "Are you checking any bags today?" • "Did you pack your bags yourself?" • "Would you prefer a window or aisle seat?" • "Your flight is on time, boarding at gate B7" • "You have a 2-hour layover in Frankfurt" • "This bag is slightly overweight. Would you like to remove some items?" • "Here's your boarding pass. Have a pleasant flight!" Typical Conversation Topics: • Document verification • Baggage allowances and fees • Seat selection • Flight information (gates, times, connections) • Special assistance needs • Upgrades Learning Objectives: • Airport vocabulary • Understanding announcements • Discussing travel documents • Handling problems (delays, overweight bags) • Numbers and times
tall-airline-16756
12/04/2025, 9:58 PMen-IN-Wavenet-A).
• Alternative (neutral international): OpenAI realtime (nova) if you prefer OpenAI's voice/timing or need Node.js parity.
• Use Gemini for strongest accent control and integration with Google Cloud TTS voice names; use OpenAI if you need a specific OpenAI voice labelled "nova".
How to decide programmatically
• Map persona attributes to plugin + voice preferences:
◦ If persona.preferred_accent contains "Indian" → choose Gemini/Google + en-IN-* voice (e.g., en-IN-Wavenet-A).
◦ If persona.preferred_accent is "Neutral International" → choose OpenAI nova or a Google neutral voice like en-US-Neural2-C.
• Fall back order: Gemini (accent fidelity) → OpenAI (neutral/alternate) → default engine.
Example Python selection snippet (conceptual)
def select_realtime_plugin(persona):
if "Indian" in persona.get("preferred_voice",""):
return {
"plugin": "google.realtime",
"model": "gemini-2.5-flash-native-audio-preview-09-2025",
"voice": "en-IN-Wavenet-A"
}
if "Neutral" in persona.get("preferred_voice",""):
return {
"plugin": "openai.realtime",
"model": "nova",
"voice": "nova" # engine-specific name
}
# default
return {
"plugin": "google.realtime",
"model": "gemini-2.5-flash-native-audio-preview-09-2025",
"voice": "Puck"
}
Example usage inside an AgentSession (Python)
• Gemini/Google:
from livekit.plugins import google
llm = google.realtime.RealtimeModel(
model="gemini-2.5-flash-native-audio-preview-09-2025",
voice="en-IN-Wavenet-A",
)
session = AgentSession(llm=llm)
• OpenAI:
from livekit.plugins import openai
llm = openai.realtime.RealtimeModel(
model="nova",
voice="nova",
)
session = AgentSession(llm=llm)
Best practices
• Store persona → plugin/voice mappings in a small config (JSON/YAML) so non-devs can tweak voices per persona.
• Provide an override mechanism so instructors can force a specific plugin/voice during a lesson.
• For fine-grained tone control, include an instructions prompt (e.g., "Speak in a calm, efficient tone, slightly formal") when creating the session.
• If you need predictable scripted lines (e.g., exact pronunciation of airport terms), combine realtime model for conversation and a dedicated TTS call (Google TTS or a separate TTS plugin) for those scripted utterances.
Would you like:
• a ready-to-use JSON persona→plugin mapping example, or
• a Node.js example that mirrors the Python snippets?modern-winter-66316
12/04/2025, 9:58 PMtall-airline-16756
12/04/2025, 9:59 PMRealtimeModel from the matching plugin, then create the AgentSession. 3) Provide an override flag for instructors/admins to force a specific backend or voice.
Example persona→plugin mapping (JSON)
{
"Priya_Checkin": {
"provider": "google",
"plugin": "livekit.plugins.google.realtime",
"model": "gemini-2.5-flash-native-audio-preview-09-2025",
"voice": "en-IN-Wavenet-A",
"instructions": "Speak in an efficient, calm, and reassuring tone."
},
"Neutral_Tutor": {
"provider": "openai",
"plugin": "livekit.plugins.openai.realtime",
"model": "nova",
"voice": "nova",
"instructions": "Friendly, neutral international accent."
}
}
Example Python selection + session creation
from livekit.plugins import google, openai
from livekit.agent import AgentSession
PERSONA_MAP = { ... } # load JSON above
def create_session_for_persona(persona_key):
cfg = PERSONA_MAP[persona_key]
if cfg["provider"] == "google":
llm = google.realtime.RealtimeModel(
model=cfg["model"],
voice=cfg["voice"],
instructions=cfg.get("instructions")
)
elif cfg["provider"] == "openai":
llm = openai.realtime.RealtimeModel(
model=cfg["model"],
voice=cfg["voice"],
instructions=cfg.get("instructions")
)
# add elifs for nova/ultravox/azure as needed
session = AgentSession(llm=llm)
return session
Best practices
• Keep voice names as explicit strings (e.g., en-IN-Wavenet-A, en-GB-Wavenet-A, nova) in the mapping.
• Use instructions for tone/personality tweaks; combine realtime backends with a dedicated TTS call for scripted lines if exact phrasing/pronunciation is required.
• Implement a fallback persona voice (e.g., Puck or a neutral nova) if the chosen backend/voice is unavailable.
• Log selected provider/model/voice per session for observability and billing reconciliation.
Would you like:
• a Node.js version of the snippets, or
• a ready-to-import YAML config with 4–6 sample personas (including Priya) to start with?modern-winter-66316
12/04/2025, 10:01 PMtall-airline-16756
12/04/2025, 10:01 PMpersonas:
Priya_Checkin:
provider: google
plugin: livekit.plugins.google.realtime
model: gemini-2.5-flash-native-audio-preview-09-2025
voice: en-IN-Wavenet-A
instructions: "Speak in an efficient, calm, and reassuring tone."
Neutral_Tutor:
provider: openai
plugin: livekit.plugins.openai.realtime
model: nova
voice: nova
instructions: "Friendly, neutral international accent."
Travel_Announcer:
provider: google
plugin: livekit.plugins.google.realtime
model: gemini-2.5-flash-native-audio-preview-09-2025
voice: en-GB-Wavenet-A
instructions: "Clear, public-announcement style."
Casual_Tutor:
provider: openai
plugin: livekit.plugins.openai.realtime
model: nova
voice: nova
instructions: "Casual, encouraging tone."
Python: load mapping and create AgentSession
import yaml
from livekit.agent import AgentSession
from livekit.plugins import google, openai # add azure, nova, ultravox as available
with open("personas.yaml", "r") as f:
cfg = yaml.safe_load(f)["personas"]
def create_session_for_persona(persona_key):
p = cfg[persona_key]
provider = p["provider"]
if provider == "google":
llm = google.realtime.RealtimeModel(
model=p["model"],
voice=p["voice"],
instructions=p.get("instructions")
)
elif provider == "openai":
llm = openai.realtime.RealtimeModel(
model=p["model"],
voice=p["voice"],
instructions=p.get("instructions")
)
# elif blocks: add azure, nova, ultravox providers similarly
session = AgentSession(llm=llm)
return session
# Example
session = create_session_for_persona("Priya_Checkin")
Node.js: load mapping and create AgentSession
const fs = require("fs");
const yaml = require("js-yaml");
const { AgentSession } = require("livekit/agent");
const google = require("livekit/plugins/google");
const openai = require("livekit/plugins/openai");
// import azure/nova/ultravox plugins similarly
const file = fs.readFileSync("personas.yaml", "utf8");
const cfg = yaml.load(file).personas;
function createSessionForPersona(personaKey) {
const p = cfg[personaKey];
const provider = p.provider;
let llm;
if (provider === "google") {
llm = new google.realtime.RealtimeModel({
model: p.model,
voice: p.voice,
instructions: p.instructions,
});
} else if (provider === "openai") {
llm = new openai.realtime.RealtimeModel({
model: p.model,
voice: p.voice,
instructions: p.instructions,
});
}
// add azure/nova/ultravox cases as needed
const session = new AgentSession({ llm });
return session;
}
// Example
const session = createSessionForPersona("Priya_Checkin");
Notes and quick best-practices
• Keep voice strings explicit in the YAML (e.g., en-IN-Wavenet-A, en-GB-Wavenet-A, nova, Puck).
• Add a fallback persona entry (e.g., provider: google, voice: Puck) and validate availability at startup.
• Use instructions to nudge tone/pace; use dedicated TTS for exact scripted lines if you need deterministic pronunciation.
• Log selected provider/model/voice per session for observability and billing mapping.
If you want, I can:
• Produce a ready-to-import JSON version,
• Add azure/nova/ultravox examples into the snippets,
• Or generate a 6-persona YAML (expanded voices) for your teacher agent. Which would you like next?modern-winter-66316
12/04/2025, 10:09 PMtall-airline-16756
12/04/2025, 10:09 PM{
"personas": {
"Priya_Checkin": {
"provider": "google",
"plugin": "livekit.plugins.google.realtime",
"model": "gemini-2.5-flash-native-audio-preview-09-2025",
"voice": "en-IN-Wavenet-A",
"instructions": "Speak in an efficient, calm, and reassuring tone."
},
"Neutral_Tutor": {
"provider": "openai",
"plugin": "livekit.plugins.openai.realtime",
"model": "nova",
"voice": "nova",
"instructions": "Friendly, neutral international accent."
},
"Travel_Announcer": {
"provider": "google",
"plugin": "livekit.plugins.google.realtime",
"model": "gemini-2.5-flash-native-audio-preview-09-2025",
"voice": "en-GB-Wavenet-A",
"instructions": "Clear, public-announcement style."
},
"Casual_Tutor": {
"provider": "openai",
"plugin": "livekit.plugins.openai.realtime",
"model": "nova",
"voice": "nova",
"instructions": "Casual, encouraging tone."
},
"Formal_Instructor": {
"provider": "google",
"plugin": "livekit.plugins.google.realtime",
"model": "gemini-2.5-flash-native-audio-preview-09-2025",
"voice": "en-US-Neural2-C",
"instructions": "Formal, clear enunciation for teaching vocabulary."
},
"Friendly_Helper": {
"provider": "openai",
"plugin": "livekit.plugins.openai.realtime",
"model": "nova",
"voice": "nova",
"instructions": "Warm, patient, and encouraging."
}
}
}
Python: load JSON and create AgentSession
import json
from livekit.agent import AgentSession
from livekit.plugins import google, openai # add azure, nova, ultravox plugins if available
with open("personas.json", "r") as f:
cfg = json.load(f)["personas"]
def create_session_for_persona(persona_key):
p = cfg[persona_key]
provider = p["provider"]
if provider == "google":
llm = google.realtime.RealtimeModel(
model=p["model"],
voice=p["voice"],
instructions=p.get("instructions")
)
elif provider == "openai":
llm = openai.realtime.RealtimeModel(
model=p["model"],
voice=p["voice"],
instructions=p.get("instructions")
)
# add azure/nova/ultravox provider branches as needed
session = AgentSession(llm=llm)
return session
# Example
session = create_session_for_persona("Priya_Checkin")
Node.js: load JSON and create AgentSession
const fs = require("fs");
const { AgentSession } = require("livekit/agent");
const google = require("livekit/plugins/google");
const openai = require("livekit/plugins/openai");
// import azure/nova/ultravox plugins similarly
const raw = fs.readFileSync("personas.json", "utf8");
const cfg = JSON.parse(raw).personas;
function createSessionForPersona(personaKey) {
const p = cfg[personaKey];
const provider = p.provider;
let llm;
if (provider === "google") {
llm = new google.realtime.RealtimeModel({
model: p.model,
voice: p.voice,
instructions: p.instructions,
});
} else if (provider === "openai") {
llm = new openai.realtime.RealtimeModel({
model: p.model,
voice: p.voice,
instructions: p.instructions,
});
}
// add azure/nova/ultravox cases as needed
const session = new AgentSession({ llm });
return session;
}
// Example
const session = createSessionForPersona("Priya_Checkin");
If you’d like, I can:
• add azure/nova/ultravox entries and code branches,
• produce a YAML version for import,
• or expand the JSON with alternate voice options per persona. Which next?modern-winter-66316
12/04/2025, 10:21 PMtall-airline-16756
12/04/2025, 10:21 PMmodern-winter-66316
12/04/2025, 10:23 PMtall-airline-16756
12/04/2025, 10:23 PMmodern-winter-66316
12/04/2025, 10:24 PMtall-airline-16756
12/04/2025, 10:24 PMmodern-winter-66316
12/04/2025, 10:27 PMtall-airline-16756
12/04/2025, 10:27 PMimport os
import logging
from livekit.plugins import google
from livekit.agent import AgentSession
from your_project.voice_provider import VoiceProvider # adjust import path
logger = logging.getLogger(__name__)
elif provider is VoiceProvider.GEMINI_REALTIME:
# Prefer persona-specific Gemini voice when available
gemini_voice = (
getattr(agent.persona, "gemini_voice", None)
or (voice if voice and voice != "default" else None)
or "Puck"
)
llm = google.realtime.RealtimeModel(
model=os.getenv(
"GEMINI_REALTIME_MODEL",
"gemini-2.5-flash-native-audio-preview-09-2025",
),
voice=gemini_voice,
instructions=getattr(agent, "instructions", None),
)
session = AgentSession(
llm=llm,
turn_detection="realtime_llm",
)
logger.info("Using Google Gemini Realtime API (voice=%s)", gemini_voice)
Notes / small improvements
• Use getattr to avoid AttributeError if agent.persona or agent.instructions are missing.
• Validate gemini_voice against a whitelist if you want to catch invalid voice names at startup.
• Keep the model string in env for easy updates; consider a config fallback file for reproducibility.
• Log provider/model/voice per session for observability and billing.
Want me to produce the variant that validates voice names against a whitelist or the Node.js equivalent?modern-winter-66316
12/04/2025, 10:28 PMtall-airline-16756
12/04/2025, 10:28 PMimport os
from livekit.agent import AgentSession
stt_model = os.getenv("LIVEKIT_STT_MODEL", "deepgram/nova-3")
llm_model = os.getenv("LIVEKIT_LLM_MODEL", "gpt-4.1-mini")
tts_model = os.getenv("LIVEKIT_TTS_MODEL", "cartesia/sonic-2")
# Append voice tag only when a non-default voice is provided
if voice and voice != "default":
tts_model = f"{tts_model}:{voice}"
session = AgentSession(
stt=stt_model,
llm=llm_model,
tts=tts_model,
turn_detection="server_vad",
allow_interruptions=False,
min_interruption_duration=1.0,
max_endpointing_delay=4.0,
)
Small improvements to consider
• Validate voice against an allowed list to avoid invalid TTS tags.
• Use getattr(agent, "voice", None) or similar if voice may be unset.
• Log chosen STT/LLM/TTS per session for observability and billing.
• If you expect occasional voice overrides, keep a config fallback and document the tag format (e.g., tts_model:voice).
Want this merged into the earlier Gemini branch example (so the same factory handles both paths)?modern-winter-66316
12/04/2025, 10:30 PMtall-airline-16756
12/04/2025, 10:30 PM