Inference Availability RealTime Voice
# ask-ai
m
Inference Availability RealTime Voice
t
Thanks for reaching out, aigentzi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking about real-time voice inference availability — here's what LiveKit supports and how to use it. • LiveKit supports real-time voice inference via the Realtime API plugins. • Available real-time models: ◦ OpenAI Realtime (Python, Node.js) ◦ Azure OpenAI Realtime (Python, Node.js) ◦ Gemini Live (Python, Node.js) ◦ Amazon Nova Sonic (Python only) ◦ Ultravox Realtime (Python only) • How to use: real-time models are exposed through each plugin's
RealtimeModel
class and can be used inside an
AgentSession
, for example:
Copy code
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 Docs
m
which gemini live model and which voices from each ?
t
You're asking which Gemini Live model and which voices are available — here’s what’s supported. • Model: ◦
gemini-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:
Copy code
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 Docs
m
can you help our AI agent know which plug in to use here , we have an AI eneglish teacher agent which has multiple personas example 4. ✈️ CHECK-IN AGENT - "Priya" Personality: Efficient, calm under pressure, helpful but follows procedures strictly. Reassuring during stressful travel moments. Suggested Voice: Indian-English accent or Neutral International • OpenAI: "nova" • Google/Gemini: en-IN-Wavenet-A or en-US-Neural2-C Opening Line:
"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
t
You're asking which realtime plugin and voice to auto-select for the "CHECK-IN AGENT - Priya" persona and how to wire that into your agent. Below are concise, actionable recommendations and example configs for automatic selection. Recommendation summary • Primary choice for Priya (Indian-English accent): Google/Gemini realtime plugin with a Google TTS voice (e.g.,
en-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)
Copy code
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:
Copy code
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:
Copy code
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?
m
his questions : When you say “all options are available with inference”, you’re using LiveKit Inference as the gateway, but under the hood it can still route to: • OpenAI Realtime • Azure OpenAI Realtime • Gemini Live • Amazon Nova Sonic • Ultravox So from the agent’s point of view: • You’re always talking to LiveKit Inference (same cluster, same billing + observability), • But you can choose which realtime provider/model/voice via the appropriate plugin (openai, google, etc.) and model/voice strings. Concretely, that means we can: • Keep a single agent (cloud-english-teacher) that: ◦ Uses livekit.plugins.openai.realtime.RealtimeModel when you pick an OpenAI persona/voice (onyx, echo, etc.). ◦ Uses livekit.plugins.google.realtime.RealtimeModel with model="gemini-2.5-flash-native-audio-preview-09-2025" and voices like en-GB-Wavenet-A when you pick Gemini personas. ◦ Potentially swap to nova / ultravox models the same way. All of that is still “within Inference” from your infra point of view, just with different realtime back‑ends and voices per persona.
t
You're correct about the architecture — I'll confirm it succinctly and give a concrete, copy‑paste‑ready approach you can drop into your agent. Acknowledgement • You're asking how to keep one agent (cloud-english-teacher) that stays within LiveKit Inference while routing realtime voice to different providers/models/voices per persona. How it works (short) • The agent always talks to LiveKit Inference (same cluster, billing, observability). • At session creation you pick a provider plugin + realtime model + voice string (openai, google, azure, nova, ultravox). • LiveKit routes audio to the selected realtime backend but your infra and billing remain unified under Inference. Recommended implementation 1) Store persona → plugin/model/voice mappings in a config file (JSON/YAML). Keep fallback values. 2) At runtime, look up the persona and instantiate the corresponding
RealtimeModel
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)
Copy code
{
  "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
Copy code
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?
m
example we need to code voices for
t
Below are ready-to-use examples you can drop into your codebase to map personas → provider/plugin → model → voice, plus Python and Node.js snippets to instantiate an AgentSession with the chosen realtime LLM. I’ll include a sample YAML persona config, a Python loader/creator, and a Node.js loader/creator. YAML persona→voice mapping (save as personas.yaml)
Copy code
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."
Python: load mapping and create AgentSession
Copy code
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
Copy code
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?
m
share this : Produce a ready-to-import JSON version,
t
Below is a ready-to-import JSON persona→voice mapping plus concise Python and Node.js examples that load the JSON and create an AgentSession. personas.json
Copy code
{
  "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
Copy code
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
Copy code
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?
m
do you thhink it is ok to have all this in code of the cloud hosted agent ? or we should be suinga database ?
t
Good question — both work, but I recommend using a small configurable datastore (database or managed config store) rather than hard‑coding persona mappings in the agent code. Quick summary and guidance: • Code (pros): simple, easy to deploy, fewer moving parts. • Code (cons): requires redeploys for changes, harder for non-dev editors, risk of config drift across environments. • Database / Config store (pros): dynamic updates without deploys, editable by non-devs (UIs/administrators), safer for multi‑region/multi‑instance deployments, better for auditing/versioning and feature flags, easier to validate and roll back. • Database / Config store (cons): slightly more infra and access-control work, need caching to avoid runtime latency. Recommended pattern 1. Store persona → provider/model/voice/instructions in a small DB or managed config service (e.g., Firestore, DynamoDB, RDS, or a config service). 2. Cache configs in the agent (in-memory with TTL) to avoid per-request DB latency. Refresh on change events or TTL expiry. 3. Expose a simple admin UI or CLI for editors to update personas (no code deploys). 4. Keep a minimal default mapping in code as a fallback for bootstrapping and recoverability. 5. Log provider/model/voice per session for observability and billing reconciliation. When to keep it in code • If you have a single, stable set of personas that rarely change and you want minimal infra, code-only is acceptable short-term. When to use DB/config store • If personas change frequently, non-devs need to edit voices/personality, you run multiple instances/regions, or you need auditing/versioning. If you want, I can: • produce a small JSON schema for the DB entries and cache TTL guidance, or • draft a simple admin UI data model and endpoints to manage personas. Which would help most?
m
they wont chgnage often so the coded route at livekit clud is best ?
t
Yes — if persona/voice mappings will change rarely, keeping them coded in your cloud-hosted agent is a reasonable, simple approach. Quick checklist to do this safely: • Keep mappings in a single focused file (JSON/YAML) separate from app logic for easy edits and reviews. • Include a small fallback/default persona in code for resilience. • Validate config at startup (schema checks) to fail fast on typos. • Log selected provider/model/voice per session for observability and billing. • Version the config file in your repo so changes are auditable and rollbacks are simple. • If you later need dynamic edits, plan a migration path to a config store and add a short TTL cache layer. Want a ready-to-commit JSON file with the checklist implemented (validation + fallback) for your repo?
m
wow so there si a lot less work ? for us
t
Yes — much less work upfront. Keeping persona mappings in code (one JSON/YAML file) simplifies deployment and maintenance when changes are rare. Quick summary of benefits you’ll get: • Fast to implement (no extra infra) • Easy code review & versioning • Predictable behavior across instances • Low operational overhead Minimal ready-to-commit bundle I can provide: • A single JSON config with fallback persona (you already have personas.json) • A small startup validation snippet to catch typos • A short checklist (startup validation, logging, versioning) Do you want the ready-to-commit JSON plus the validation snippet and checklist now?
m
dos thsi look coirect : elif provider is VoiceProvider.GEMINI_REALTIME: from livekit.plugins import google # Prefer persona-specific Gemini voice when available gemini_voice = ( agent.persona.gemini_voice or (voice if voice != "default" else None) or "Puck" ) session = AgentSession( llm=google.realtime.RealtimeModel( model=os.getenv( "GEMINI_REALTIME_MODEL", "gemini-2.5-flash-native-audio-preview-09-2025", ), voice=gemini_voice, instructions=agent.instructions, ), turn_detection="realtime_llm", ) logger.info("Using Google Gemini Realtime API (voice=%s)", gemini_voice)
t
You're on the right track — the logic and fallbacks make sense. I cleaned and corrected the snippet (syntax, imports, env lookup, enum usage, logging) and added a couple of small best-practice notes. Corrected Python snippet
Copy code
import 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?
m
this else: 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") if 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, )
t
Looks good — the logic is sensible. I cleaned and corrected formatting, added safety checks, and a couple of small best-practice suggestions. Corrected snippet
Copy code
import 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)?
m
agent = EnglishTeacherAgent(scenario=scenario, level=level) logger.info("EnglishTeacherAgent created successfully (persona=%s)", agent.persona.name)
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!