# Whisper for automatic speech recognition

{% embed url="<https://openai.com/blog/whisper>" %}

Whisper is an Open Source, general-purpose speech recognition model that offers a very simple API to use its powers:

{% code title="" lineNumbers="true" %}

```python
import whisper

model = whisper.load_model("base")

# load audio and pad/trim it to fit 30 seconds
audio = whisper.load_audio("audio.mp3")
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).to(model.device)

# detect the spoken language
_, probs = model.detect_language(mel)
print(f"Detected language: {max(probs, key=probs.get)}")

# decode the audio
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)

# print the recognized text
print(result.text)
```

{% endcode %}

## A perfect example of its power

<figure><img src="https://4092288392-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY8AeUFC5KYkaUv3lbFhX%2Fuploads%2FAWcSYmergJajHxELAL7x%2Fimage.png?alt=media&#x26;token=ce91bc00-df64-4927-95a6-307a984c178d" alt=""><figcaption></figcaption></figure>

{% embed url="<https://huggingface.co/spaces/vumichien/whisper-speaker-diarization>" %}

{% embed url="<https://www.youtube.com/watch?v=wAUYA2AtEyM>" %}
