busy-monitor-72069
09/12/2025, 7:31 PMtall-airline-16756
09/12/2025, 7:31 PMtall-airline-16756
09/12/2025, 7:32 PMbusy-monitor-72069
09/12/2025, 7:33 PMtall-airline-16756
09/12/2025, 7:34 PMclass LanguageSwitcherAgent(Agent):
def __init__(self):
super().__init__(
stt=deepgram.STT(
model="nova-2-general",
language="en"
),
tts=elevenlabs.TTS(
model="eleven_turbo_v2_5",
language="en"
)
)
1. Define Supported Languages: It’s helpful to map language codes to their names and configurations like this:
self.language_names = {
"en": "English",
"es": "Spanish",
"fr": "French",
"de": "German",
"it": "Italian"
}
self.deepgram_language_codes = {
"en": "en",
"es": "es",
"fr": "fr-CA",
"de": "de",
"it": "it"
}
1. Implement Language Switching Logic: This part updates your TTS and STT options dynamically whenever the language changes:
async def _switch_language(self, language_code: str):
if self.tts is not None:
self.tts.update_options(language=language_code)
if self.stt is not None:
deepgram_language = self.deepgram_language_codes.get(language_code, language_code)
self.stt.update_options(language=deepgram_language)
1. Create Function Tools: These tools let you switch languages programmatically, making your app more flexible:
@function_tool
async def switch_to_spanish(self):
await self._switch_language("es")
Just so you know, LiveKit's MultilingualModel supports English plus 13 other languages. It uses the language detected by the STT plugin to manage turn detection in multilingual conversations, which is pretty neat!
If you’d like any more help implementing this or have questions along the way, please don’t hesitate to reach out. I’m here to support you!
Sources: pipeline-tts/tts_comparison.py | LiveKit turn detector plugin | LiveKit Docs