how to change language in realtime agents when use...
# ask-ai
s
how to change language in realtime agents when user mentions its preference..
t
Thanks for reaching out, AANKIT. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It’s great that you want to make your real-time agents more responsive to users’ language preferences! To help you with that, you can set up a dynamic language-switching mechanism that listens for users mentioning their preferred language and then updates both the Text-to-Speech (TTS) and Speech-to-Text (STT) settings accordingly. Here’s a friendly overview of the steps you can take: 1. Keep a handy list of language mappings for your TTS and STT setups, like English, Spanish, French, and so on. 2. Create a helper method that can switch languages on the fly by updating the TTS and STT options. 3. Use function tools tailored for each supported language so your agent can smoothly switch languages when the user requests it. 4. Don’t forget to send a warm confirmation message in the new language, so the user knows the change took place. If you’d like, I can share a detailed example with code snippets and configuration tips to make this even easier. Just let me know—I’m here to help! Sources: docs/index.yaml
s
voice_params = texttospeech.VoiceSelectionParams( _language_code_="hi-IN", _ssml_gender_=texttospeech.SsmlVoiceGender.FEMALE, ) self.tts.update_options(voice=voice_params) giving error Traceback (most recent call last): File "/Users/aankitroy/Workspace/voice-agents/livekit-voice-agent/agent.py", line 100, in change_language self.tts.update_options(voice=voice_params) ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NotGiven' object has no attribute 'update_options'
t
It looks like the error
AttributeError: 'NotGiven' object has no attribute 'update_options'
is happening because the
self.tts
object hasn’t been properly set up yet and is still holding the
NOT_GIVEN
sentinel value instead of a valid TTS instance. This usually means the TTS configuration might be incomplete or hasn’t been initialized correctly. Here’s a friendly guide to help you resolve this: 1. Make sure the TTS object is correctly created before you try to call
update_options
. For example:
Copy code
from livekit.plugins.google import TTS
self.tts = TTS(voice_name="en-US-Wavenet-A")
1. Before calling
update_options
, check if
self.tts
is valid by using the
is_given()
utility like this:
Copy code
from livekit.agents.utils import is_given
if is_given(self.tts):
    self.tts.update_options(voice=voice_params)
else:
    raise ValueError("TTS instance is not configured")
1. Take a moment to review how your agent or session is initialized to ensure the TTS plugin is properly injected and not left as
NOT_GIVEN
. If you’d like, I’m here to help you debug further or walk you through setting up the TTS instance. Just let me know! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Hume TTS plugin guide | LiveKit Docs
s
self.tts = TTS(_voice_name_="hi-IN-Wavenet-Aoede") if is_given(self.tts): self.tts.update_options(language="hi-IN") _else_: raise ValueError("TTS instance is not configured") giving error Traceback (most recent call last): File "/Users/aankitroy/Workspace/voice-agents/livekit-voice-agent/agent.py", line 97, in change_language self.tts = TTS(voice_name="hi-IN-Wavenet-Aoede") ^^^^^^^^ AttributeError: property 'tts' of 'FlightBookingAgent' object has no setter
t
It looks like you're encountering the error
AttributeError: property 'tts' of 'FlightBookingAgent' object has no setter
, which happens because the
tts
attribute in the agent class is set up as a read-only property. This means once the agent is initialized, you can’t reassign
tts
. Here are a few friendly ways to work around this: 1. Set the TTS instance right when you initialize the agent, like this:
Copy code
agent = FlightBookingAgent(
    instructions="You are a flight booking assistant.",
    tts=TTS(voice_name="hi-IN-Wavenet-Aoede")
)
1. If you want to change the TTS settings while the agent is running, you can use
update_options
to tweak the configuration:
Copy code
self.tts.update_options(language="hi-IN")
1. And if you ever need to swap out the whole TTS setup, the best approach is to create a new
AgentSession
with the TTS configuration you want. Feel free to reach out if you want me to walk you through any of these steps or if you have any other questions—I’m here to help! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/__init__.py | docs/index.yaml