Skip to main content

Overview

Whisper includes built-in language detection that can identify the spoken language in audio files. This feature analyzes the first 30 seconds of audio and returns probability distributions over all supported languages.

Automatic Detection

CLI

By default, Whisper automatically detects the language when not specified:
Output:
To skip detection and improve performance, specify the language:

Python API

Omit the language parameter for automatic detection:

The detect_language() Function

For standalone language detection without transcription, use the detect_language() function:

Function Signature

Basic Usage

Return Values

The function returns:
  1. language_tokens - Tensor of most probable language token IDs
  2. language_probs - Dictionary mapping language codes to probabilities

Practical Examples

1. Batch Language Detection

2. Language-Specific Routing

3. Confidence Threshold

4. Multilingual Audio Segmentation

5. Integration with Transcription

Advanced: Language-Specific Tokenizers

Different languages use different tokenizers. Understanding this helps with lower-level API usage:

Supported Languages

Whisper supports 99 languages. Common language codes:
  • en - English
  • es - Spanish
  • fr - French
  • de - German
  • it - Italian
  • pt - Portuguese
For the complete list, see tokenizer.py.

Model Requirements

Language detection only works with multilingual models. English-only models (tiny.en, base.en, small.en, medium.en) cannot detect languages.

Performance Considerations

Detection Speed

Language detection analyzes only the first 30 seconds of audio:

Skip Detection for Known Languages

If you know the language, skip detection to save time:
For batch processing of files in the same language, detect once and reuse the language code for subsequent files.