how i can detect user speech language in livekit
# ask-ai
b
how i can detect user speech language in livekit
t
Thanks for reaching out, Aleh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring how to detect user speech language in LiveKit! To make this easier for you, you can use speech-to-text (STT) plugins that come with automatic language detection. Here are some friendly options you might find helpful: • Google STT Plugin: Just enable
detect_language=True
and, if you like, provide candidate languages using the
languages
parameter. • OpenAI STT Plugin: Simply set
detect_language=True
when you initialize it. • Azure STT Plugin: You can specify multiple languages in the
language
parameter to let it detect automatically. • LiveKit Inference: Try multilingual models like Cartesia or Deepgram—they’re great at automatic language detection. If you'd like, I’d be happy to walk you through setting up any specific plugin. Just let me know which one you’re interested in! Sources: livekit-plugins/livekit-plugins-azure/livekit/plugins/azure/stt.py | CLOVA STT plugin guide | LiveKit Docs | Speech-to-text (STT) models | LiveKit Docs | pipeline-tts/changing_language/README.md
b
• Azure STT Plugin: You can specify multiple languages in the
language
parameter to let it detect automatically. plovide example please
t
I'd love to help you get started with configuring the Azure STT plugin for automatic language detection! Here's a simple example where you can specify multiple languages for the plugin to consider:
Copy code
from livekit.plugins.azure import STT

# Initialize the Azure STT plugin with multiple candidate languages
stt = STT(
    language=["en-US", "de-DE", "fr-FR"]  # List of candidate languages for detection
)

# Use the STT instance to process audio and detect the language
speech_event = await stt.recognize(audio_buffer)

# Access the detected language from the result
detected_language = speech_event.language
print(f"Detected language: {detected_language}")
With this setup, Azure will automatically figure out which language is being spoken from the options you provided (
en-US
,
de-DE
,
fr-FR
). If you have any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help!
b
deadsage14235icloud.com@MacBook-Pro backend % uv run main.py console Traceback (most recent call last): File "/Users/deadsage14235icloud.com/Documents/scnsoft_workflow/AI/ai_bot_scenario_1/backend/main.py", line 16, in <module> from core.session.console_setup import console_entrypoint File "/Users/deadsage14235icloud.com/Documents/scnsoft_workflow/AI/ai_bot_scenario_1/backend/core/session/console_setup.py", line 8, in <module> from core.session.session_builder import SessionBuilder File "/Users/deadsage14235icloud.com/Documents/scnsoft_workflow/AI/ai_bot_scenario_1/backend/core/session/session_builder.py", line 11, in <module> from livekit.plugins.azure import STT ModuleNotFoundError: No module named 'livekit.plugins.azure' deadsage14235icloud.com@MacBook-Pro backend %
t
It looks like you're seeing the error
ModuleNotFoundError: No module named 'livekit.plugins.azure'
because the Azure plugin package isn’t installed yet. No worries, I’m here to help you get this sorted out! Here’s what you can do: 1. First, install the Azure plugin package using pip:
Copy code
pip install livekit-plugins-azure
1. Next, make sure to set your Azure credentials as environment variables like this:
Copy code
export AZURE_SPEECH_KEY="your_speech_key"
export AZURE_SPEECH_REGION="your_region"
1. Once that’s done, you’ll be able to import the Azure plugin components without any trouble:
Copy code
from livekit.plugins.azure import STT, TTS
If you run into any other bumps or have questions along the way, please don’t hesitate to reach out. I’m here to help! Sources: Azure Speech TTS plugin guide | LiveKit Docs | livekit-plugins/livekit-plugins-azure/livekit/plugins/azure/log.py | Azure Speech STT plugin guide | LiveKit Docs
b
ok, i want to try approch detecting language using turn detection my current setup is
Copy code
tts = TTS.with_azure(
    azure_endpoint=azure_openai_tts_settings.endpoint,
    api_key=azure_openai_tts_settings.api_key,
    model=agent_settings.TTS_MODEL,
    azure_deployment=agent_settings.TTS_MODEL,
    voice=agent_settings.TTS_VOICE,
    speed=agent_settings.TTS_SPEED,
    instructions=vibe_instructions,
)

llm = RealtimeModel.with_azure(
    azure_deployment=agent_settings.LLM_MODEL,
    voice=agent_settings.LLM_VOICE,
    modalities=["text"],
    turn_detection=TurnDetection(
        type="semantic_vad",
        eagerness="auto",
        create_response=True,
        interrupt_response=True,
    ),
)
t
To help you detect language using turn detection in LiveKit, you can set up the
TurnDetection
feature with a multilingual model. Here’s a friendly example to guide you through:
Copy code
from livekit.plugins.turn_detector.multilingual import MultilingualModel
from livekit.plugins.azure import STT
from livekit.plugins.openai import RealtimeModel

# Initialize the turn detector with a multilingual model
turn_detection = MultilingualModel()

# Configure the STT plugin for multilingual input
stt = STT(
    language=["en-US", "de-DE", "fr-FR"]  # Candidate languages for detection
)

# Set up the Realtime LLM with turn detection
llm = RealtimeModel(
    turn_detection=turn_detection,
    modalities=["text"],
    create_response=True,
    interrupt_response=True,
)

# Use these components in your agent session
session = AgentSession(
    stt=stt,
    llm=llm,
    turn_detection=turn_detection
)
This setup combines a multilingual STT with a semantic turn detector to smoothly manage both language detection and turn-taking. If you have any questions or need a hand with this, please don’t hesitate to reach out—I’m here to help! Sources: examples/voice_agents/realtime_turn_detector.py | Building the all-in-one platform for voice AI agents | complex-agents/turn-taking/README.md
b
what that could be? Turn detector does not support language
Copy code
session = AgentSession[SessionState](
    userdata=session_state,
    allow_interruptions=agent_settings.ALLOW_INTERRUPTIONS,
    tts=tts,
    llm=llm,
    stt=stt_impl,
    turn_detection=MultilingualModel()
)
t
I'm sorry to hear you're encountering the error "Turn detector does not support language." This usually happens when the turn detector model you're using doesn't support the language detected by your STT system. Let's work through this together to get it sorted out: 1. First, please make sure you're using the
MultilingualModel
for turn detection, as it supports multiple languages:
Copy code
from livekit.plugins.turn_detector.multilingual import MultilingualModel

turn_detection = MultilingualModel()
1. Next, double-check that your STT configuration is set to use compatible language codes. The supported languages include English, Spanish, French, German, Italian, Portuguese, Dutch, Chinese, Japanese, Korean, Indonesian, Turkish, and Russian. 2. Also, don't forget to download the necessary model files before using the system for the first time:
Copy code
python your_agent.py download-files
1. Finally, please verify that the language detected by your STT system matches one of the supported languages in the turn detector. If you continue to experience issues or have any questions along the way, please feel free to reach out. I'm here to help! Sources: plugins/livekit/src/turn_detector/index.ts | livekit-plugins/livekit-plugins-turn-detector/livekit/plugins/turn_detector... | LiveKit turn detector plugin | LiveKit Docs