Whisper can transcribe speech in many languages, but only if it knows — or guesses — which language it is hearing. Guess wrong and the transcript comes out garbled, or in the wrong language entirely. Before you transcribe a recording whose language you are unsure about, ask Whisper itself: it can perform language identification as one of its built-in multitask abilities, and its Python API exposes that check directly as detect_language().
Ask Whisper what language it hears
The Whisper README’s own Python example loads a model, prepares the audio, and detects the spoken language:
import whisper
model = whisper.load_model("turbo")
# load audio and pad/trim it to fit 30 seconds
audio = whisper.load_audio("practice-recording.wav")
audio = whisper.pad_or_trim(audio)
# make log-Mel spectrogram and move to the same device as the model
mel = whisper.log_mel_spectrogram(audio, n_mels=model.dims.n_mels).to(model.device)
# detect the spoken language
_, probs = model.detect_language(mel)
print(f"Detected language: {max(probs, key=probs.get)}")
probs is a dictionary mapping language codes to probabilities, and max(probs, key=probs.get) picks the language with the highest probability. Two details matter. First, use a multilingual model: the README’s model table lists English-only .en models (tiny.en, base.en, small.en, medium.en) separately from the multilingual ones (tiny, base, small, medium, large, turbo), and detection only makes sense with a multilingual model. Second, the check reads only the first 30 seconds — pad_or_trim pads or trims the audio to fit 30 seconds — so for a long recording, check the opening passage and remember the rest could switch languages.
Try it: detect the language of two practice recordings
Record two short fictional sentences and save them as separate files: in English, “The lighthouse keeper named Mara checked the lamp at noon.” as practice-english.wav, and in Japanese, “Mara wa toudai no ban’nin desu.” as practice-japanese.wav. Run the script above on each file, changing only the filename, and check the printed language against this table:
| Recording | Detected language you should see | If you do not see it |
|---|---|---|
practice-english.wav |
en, with a probability close to 1 |
The recording is mostly silence or noise — re-record it clearly |
practice-japanese.wav |
ja, with a probability close to 1 |
You used an English-only .en model, or the wrong file |
Once the detected language matches the language you recorded, transcribe with that language named explicitly — for example, whisper practice-japanese.wav --language Japanese — instead of letting Whisper guess again. Expected result. We checked the Whisper README. We did not run Whisper on a sample recording.
Limits
Detection is a guess with a probability, not a certainty: short clips, heavy accents, background noise, and mixed-language speech can all lower the probability or flip the answer, so treat a low probability as “check by listening” rather than a fact. The check only looks at the first 30 seconds, so it says nothing about a language change later in a long recording. And detection does not transcribe anything — it only tells you which language to pass to the transcription step. We did not run Whisper, so no detected language here is a measured result.
