Whisper is a multitask, multilingual model trained on 680,000 hours of diverse audio data. Its transformer-based architecture transcribes, translates, and identifies languages directly from raw audio—all in a single end-to-end pipeline.
Speech-to-text technology has advanced significantly in recent years, with OpenAI’s Whisper leading the way. Whisper is an automatic speech recognition (ASR) system that utilizes advanced machine learning methods and a straightforward design to transcribe and translate speech in 99 languages. In this blog, I’ll break down how Whisper works, step by step, and demonstrate how it can be used in simple Subtitle Generator projects.
At its core, Whisper is an encoder-decoder transformer model trained on 680,000 hours of diverse audio data. Unlike traditional Automatic Speech Recognition (ASR) systems that rely on complex pipelines with separate components for acoustic modeling and language processing, Whisper unifies these tasks into a single neural network. This approach allows it to handle accents, background noise, and multilingual inputs more robustly.
The model’s versatility comes from its ability to perform multiple tasks—like transcription, translation, and language identification—using a unified architecture. By conditioning the decoder with special tokens (e.g., <|en|> for English or <|translate|> for translation), Whisper dynamically adapts to the user’s needs.
Whisper begins by converting raw audio into a log-Mel spectrogram, a mathematical representation that captures frequency patterns over time. It transforms chaotic sound waves into a structured format the model can analyze. This spectrogram is generated by:
[-1, 1] to stabilize training.
The encoder outputs a high-dimensional representation of the audio, capturing both acoustic and linguistic features (good blog talking about it link).
The spectrogram first passes through two 1D convolutional layers (kernel size 3), which act as a “stem” to detect local acoustic patterns like phonemes or formants. These layers:
Since audio is a time-series, Whisper adds sinusoidal positional embeddings to the spectrogram. These embeddings encode the position of each 40ms audio frame, allowing the model to understand temporal order—crucial for distinguishing sequences like “cat” vs. “act”.
The core of the encoder is a stack of 32 transformer blocks (for large models). Each block includes:
Through these layers, the encoder gradually builds a high-dimensional representation (1,500 tokens of 1,280 dimensions for 30-second audio) that encapsulates both acoustic details (e.g., pitch) and linguistic context
The decoder generates text one token at a time using an autoregressive process:
The decoder predicts text tokens autoregressively, one word at a time, using:
<|transcribe|> or <|translate|> guide the decoder49.For example, when translating French to English, the decoder might process: <|startoftranscript|><|fr|><|translate|> → “Bonjour” → “Hello”
This pipeline ensures Whisper handles everything from podcasts to phone calls seamlessly.
Using Whisper is straightforward with Open AI whisper Library
To use Whisper, install it via pip:
pip install openai-whisperHere’s how to transcribe an audio file in Python:
import whisper
# Load the model (choose 'tiny', 'base', 'small', 'medium', or 'large')
model = whisper.load_model("base")
# Transcribe audio
result = model.transcribe("audio.mp3")
print(result["text"])model.transcribe(..., task="translate") to convert non-English speech to English text.model.transcribe(..., verbose=True).You can reference the link on Kaggle