I want to change the stt and tts language in the r...
# ask-ai
g
I want to change the stt and tts language in the runtime, is there any way to do it. Based on the conversiation can i switch the langauge
t
Thanks for reaching out, ashutosh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking whether you can switch STT and TTS languages at runtime and keep the conversation context. Yes — you can. What you can do • Call
update_options()
on the agent session's STT and TTS instances to change their
language
(or provider-specific language code) during a running session. • After updating both, the agent can continue the same conversation and respond in the new language (commonly you’ll confirm the switch by greeting in the new language). Implementation pattern (example)
Copy code
# pseudocode example
self.session.tts.update_options(language="es")        # TTS -> Spanish
self.session.stt.update_options(language="es-US")     # STT -> provider-specific code
# continue the session; agent can greet in Spanish
Notes and options • Some STT providers (e.g., Gladia) support code-switching and real-time translation; you can enable those features if you expect mixed-language input. • Use provider-specific language codes when required (e.g., Deepgram vs. Gladia may differ). Quick question to finish: Which STT/TTS providers and which target language(s) do you want to switch to? I can give exact code and language codes for your setup. Sources: ElevenLabs Change Language | LiveKit docs | Gladia STT plugin guide | LiveKit docs | TTS Translator with Gladia STT | LiveKit docs
g
provide me a code snipit
t
Thanks — you want a concise code snippet showing how to switch STT and TTS languages at runtime. Below is a minimal Python example using the
AgentSession
pattern and
update_options()
calls described earlier. Replace provider classes, language codes, and method names with those from your actual SDK if they differ.
Copy code
# Example: switch STT and TTS language at runtime in an AgentSession

class MultilingualAgent:
    def __init__(self, session):
        # session should expose .tts and .stt instances and a send_message/handle flow
        self.session = session

    def handle_user_request(self, text_or_audio):
        # normal handling (speech input -> transcribe -> respond)
        transcript = self.session.stt.transcribe(text_or_audio)
        response_text = self.generate_response(transcript)
        self.session.tts.speak(response_text)

    def switch_language(self, tts_language_code, stt_language_code):
        """
        Change TTS and STT languages at runtime.
        tts_language_code: provider-specific TTS language (e.g., "es" or "es-ES")
        stt_language_code: provider-specific STT language (e.g., "es-US" or "es-ES")
        """
        # update TTS
        self.session.tts.update_options(language=tts_language_code)

        # update STT
        self.session.stt.update_options(language=stt_language_code)

        # optional: confirm the switch vocally in the new language
        confirmation = {
            "es": "Idioma cambiado a español.",
            "en": "Language switched to English.",
        }.get(tts_language_code.split("-")[0], "Language switched.")
        self.session.tts.speak(confirmation)

    def generate_response(self, transcript):
        # stub: implement your agent response generation
        return f"You said: {transcript}"
Usage example:
Copy code
# create session with provider-specific stt/tts instances
session = AgentSession(stt=DeepgramSTT(...), tts=ElevenLabsTTS(...))
agent = MultilingualAgent(session)

# normal flow
agent.handle_user_request(audio_input)

# on user request to switch languages (e.g., "Switch to Spanish")
agent.switch_language(tts_language_code="es-ES", stt_language_code="es-US")

# continue handling further input in Spanish
agent.handle_user_request(next_audio_input)
If you tell me which STT/TTS providers you use (e.g., Deepgram, Gladia, ElevenLabs) and the exact target language codes, I can give a provider-specific snippet with correct language codes and any provider-specific flags (e.g., code-switching or translation options).
g
can we update the stt in the running session wit the updated language
t
Yes — you can update the STT language during a running session. What to do • Call
update_options()
on the session's STT instance with the new language code. • Continue the session; the STT will transcribe using the new language without needing to restart the session. Minimal Python snippet
Copy code
# assume session.stt exposes update_options(language=...)
# switch STT language at runtime
new_stt_language = "es-ES"  # provider-specific code
session.stt.update_options(language=new_stt_language)

# continue handling audio; subsequent transcriptions use the new language
transcript = session.stt.transcribe(live_audio_chunk)
Would you like a provider-specific snippet (Deepgram, Gladia, etc.) or examples for handling mixed-language/code-switching?
g
i want to update the stt model in therrunning session dynamically
t
You're able to update the STT model (and language) dynamically in a running session by calling
update_options()
on the active
stt
instance. Below is a concise provider-agnostic Python example plus provider-specific notes. Minimal async example
Copy code
# Initialize session with an STT instance (must be an STT object, not a shorthand string)
session = AgentSession(
    stt=inference.STT(model="deepgram/flux-general", language="en"),
    tts=inference.TTS(...),
)

# Later, during the running session, update model and/or language
await session.stt.update_options(model="deepgram/flux-translate", language="es")

# Subsequent transcriptions use the new model/language
transcript = await session.stt.transcribe(audio_chunk)
Key notes • The
stt
field must be an STT plugin or
inference.STT
instance; shorthand string configs (e.g.,
stt="deepgram/flux-general:en"
) do not support
update_options
. • Supported providers include Deepgram, Gladia, Cartesia, fal, OpenAI, ElevenLabs, etc. Provider-specific language codes or model names may differ. • For Deepgram you can use
multi
for multilingual input or specific codes like
"es"
,
"fr"
. • Cartesia may require language suffixes (e.g.,
":en"
). Check the provider's code for exact model/language identifiers. • If you expect mixed-language input, some providers (Gladia) support code-switching and translation flags (e.g.,
code_switching=True
,
translation_enabled=True
). If you tell me which STT provider and the exact model/language you want to switch to, I’ll give a provider-specific snippet with correct model names and language codes. Sources: Speech-to-text (STT) models | LiveKit Docs | Cartesia STT | LiveKit docs | fal STT plugin guide | LiveKit docs | Gladia STT plugin guide | LiveKit docs | ElevenLabs STT | LiveKit docs
g
stt dont have any update_options
t
Thanks — you're saying your
stt
instance doesn't have
update_options
. That usually means it was created as a shorthand/string descriptor or with an SDK/provider that doesn't expose the plugin API. What I recommend • If you want dynamic updates, initialize STT as a plugin object (not a string). Plugin-based STT instances expose
update_options
. • Tell me which STT provider and how you currently create
stt
(paste the few lines of code). I’ll give an exact snippet to initialize the plugin and show how to call
update_options
to change model/language at runtime. Quick example (Deepgram plugin vs shorthand) • Shorthand (no update_options): ◦ stt="deepgram/nova-2:en" ← does not expose
update_options
• Plugin (supports update_options): ◦ from livekit.plugins import deepgram ◦ stt = deepgram.STT(model="nova-2", language="en") ◦ await stt.update_options(model="nova-3", language="es") Please paste your STT initialization code or name the provider and I'll provide the provider-specific code to enable dynamic model/language updates. Sources: Deepgram STT plugin guide | LiveKit docs | ElevenLabs Change Language | LiveKit docs | Deepgram STT | LiveKit docs