openai/whisper · error · ValueError
Unsupported language: {language}
Error message
Unsupported language: {language} What it means
get_tokenizer() accepts a language only if it is either a key of LANGUAGES (a code like 'en', 'de') or a key of TO_LANGUAGE_CODE (an English name like 'english', 'german', which it then converts). Anything else — before the multilingual branch even runs — raises ValueError('Unsupported language: ...').
Source
Thrown at whisper/tokenizer.py:380
special_tokens=special_tokens,
)
@lru_cache(maxsize=None)
def get_tokenizer(
multilingual: bool,
*,
num_languages: int = 99,
language: Optional[str] = None,
task: Optional[str] = None, # Literal["transcribe", "translate", None]
) -> Tokenizer:
if language is not None:
language = language.lower()
if language not in LANGUAGES:
if language in TO_LANGUAGE_CODE:
language = TO_LANGUAGE_CODE[language]
else:
raise ValueError(f"Unsupported language: {language}")
if multilingual:
encoding_name = "multilingual"
language = language or "en"
task = task or "transcribe"
else:
encoding_name = "gpt2"
language = None
task = None
encoding = get_encoding(name=encoding_name, num_languages=num_languages)
return Tokenizer(
encoding=encoding, num_languages=num_languages, language=language, task=task
)
View on GitHub (pinned to 5f86d1d863)
Solutions
- Normalize to the base two-letter code: language.split('-')[0].strip().lower() and verify against whisper.tokenizer.LANGUAGES
- Pass the English display name ('german') only if spelled exactly as in TO_LANGUAGE_CODE
- Validate user-supplied languages against whisper.tokenizer.LANGUAGES before calling transcribe()
Example fix
# before
result = whisper.transcribe(model, path, language="zh-CN") # ValueError
# after
from whisper.tokenizer import LANGUAGES
lang = "zh-CN".split("-")[0].strip().lower()
assert lang in LANGUAGES, f"unsupported: {lang}"
result = whisper.transcribe(model, path, language=lang) Defensive patterns
Strategy: validation
Validate before calling
from whisper.tokenizer import LANGUAGES, TO_LANGUAGE_CODE
def normalize_language(raw: str) -> str:
lang = raw.strip().lower()
if lang in LANGUAGES:
return lang
if lang in TO_LANGUAGE_CODE:
return TO_LANGUAGE_CODE[lang]
base = lang.split("-")[0].split("_")[0]
if base in LANGUAGES:
return base
raise ValueError(f"Unsupported language: {raw}") Type guard
def is_supported_language(v: str) -> bool:
v = v.strip().lower()
return v in LANGUAGES or v in TO_LANGUAGE_CODE Prevention
- Normalize BCP-47 tags to the primary subtag before passing language to whisper
- Expose a whitelist of supported languages at your API boundary and reject others with a 4xx
When it happens
Trigger: get_tokenizer(True, language='zh-CN') (locale form instead of 'zh'); language='eng' (ISO-639-2/b code); passing None-with-typo or a name with trailing whitespace ('english ') so neither dict matches; also raised via transcribe(model, path, language=<bad>).
Common situations: Feeding BCP-47 locale tags from web requests directly into language=; using 3-letter ISO codes from other datasets; uppercase already handled (.lower() is applied) but hyphens/whitespace are not.
Related errors
- Language {language} not found in tokenizer.
- {download_target} exists and is not a regular file
- Model {name} not found; available models = {available_models
- This model doesn't have language tokens so it can't perform
- This tokenizer does not have language token configured
AI-assisted analysis of openai/whisper@5f86d1d863 (2026-08-14).
Data as JSON: /api/errors/0c09b5450a5dc463.
Report an issue: GitHub.