Is there a LanguageCode import?
# ask-ai
b
Is there a LanguageCode import?
✅ 1
t
Thanks for reaching out, Andrii. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — regarding your question about a LanguageCode import: • In Python you can import
LanguageCode
from `livekit.agents`:
Copy code
from livekit.agents import LanguageCode
• In Node.js there isn’t a
LanguageCode
export; use
normalizeLanguage()
from
@livekit/agents
instead:
Copy code
import { normalizeLanguage } from '@livekit/agents';
`LanguageCode`/`normalizeLanguage()` accepts common formats (ISO 639-1, BCP-47, ISO 639-3, names, underscored variants) and normalizes them to BCP-47. Sources: Speech-to-text (STT) models overview | LiveKit Documentation, with interactive elements
b
Is
language
required in
SpeechData
object initialization?
t
Which SDK/language are you using (Python, Node.js, or other)? Could you paste the
SpeechData
initialization code you're using or the package/version so I can confirm whether
language
is required? , with interactive elements
b
Python
t
Thanks — regarding whether
language
is required in
SpeechData
for Python: • No, you do not need to set
language
when initializing
SpeechData
. •
language
is populated by STT providers when they return language-detection results (e.g., Deepgram with
detect_language=True
, Soniox with
enable_language_identification=True
). It’s a read-only output, not an input you must provide. If you want, tell me which STT provider and example code you’re using and I can show how to enable language detection and where the detected
language
appears in the
SpeechEvent
output. Sources: Speech-to-text (STT) models overview | LiveKit Documentation | Text-to-speech (TTS) models overview | LiveKit Documentation | AssemblyAI STT | LiveKit Documentation | Smallest AI STT plugin guide | LiveKit Documentation | Soniox STT plugin guide | LiveKit Documentation, with interactive elements
b
Argument missing for parameter "language"PylancereportCallIssue Missing positional argument "language" in call to "SpeechData"Mypycall-arg class SpeechData( language: LanguageCode, text: str, start_time: float = 0, end_time: float = 0, confidence: float = 0, speaker_id: str | Unknown = None, is_primary_speaker: bool | Unknown = None, words: list[TimedString] | Unknown = None, source_languages: list[LanguageCode] | Unknown = None, source_texts: list[str] | Unknown = None,
t
Thanks — you're right to call this out. Short answer: the Python
SpeechData
class requires a
language
positional argument when you instantiate it. Even though STT providers populate
language
for events, if you create a
SpeechData
instance yourself you must pass
language
. What you can do: • Import
LanguageCode
and pass a value when constructing:
Copy code
from livekit.agents import LanguageCode

sd = SpeechData(
    LanguageCode("en-US"),
    text="hello",
    start_time=0.0,
    end_time=1.0,
)
• If you don't know the language (e.g., you want a placeholder until detection runs), pass a sensible default like
"und"
or
"en-US"
depending on your flow:
Copy code
sd = SpeechData(LanguageCode("und"), text="...", ...)
If you share the code where you create
SpeechData
, I can suggest the exact minimal change to satisfy Pylance/mypy. , with interactive elements