A mel spectrogram is a two-dimensional representation of audio in which the horizontal axis is time, the vertical axis is frequency mapped onto the perceptually motivated mel scale, and each cell holds the energy of a frequency band in a short window, usually on a logarithmic scale. In speech & language AI it is the default acoustic feature for speech recognition, speaker analysis and text-to-speech.
The representation compresses a raw waveform of tens of thousands of samples per second into roughly 80 to 128 values per 10 milliseconds, keeping the information that matters for human hearing while discarding fine detail that neural networks rarely need. Its popularity comes from this balance of compactness and fidelity.
How a mel spectrogram is computed
The computation starts with a short-time Fourier transform (STFT). The waveform is cut into overlapping frames, each frame is multiplied by a window function such as Hann, and a fast Fourier transform turns it into a spectrum. Squaring the magnitudes gives a power spectrogram with linearly spaced frequency bins.
Next, a mel filterbank of overlapping triangular filters is applied. Filters are narrow and dense at low frequencies and wide and sparse at high frequencies, so the output mirrors the finer pitch resolution of human hearing below about 1 kHz. Finally, the energies are compressed with a logarithm or a decibel conversion, producing the log-mel spectrogram that models actually consume.
The table below lists the processing steps and the effect each one has on the signal.
| Step | Operation | Effect on the data |
|---|---|---|
| Framing | Split audio into short overlapping windows | Creates the time axis |
| Windowing | Multiply each frame by a taper | Reduces spectral leakage |
| FFT | Transform each frame to frequency | Linear frequency bins |
| Power | Square the magnitude | Energy per bin |
| Mel filterbank | Sum energy under triangular filters | Perceptual frequency bands |
| Log compression | Apply log or decibel scaling | Matches loudness perception, stabilizes training |
The mel scale and why it is used
The mel scale maps physical frequency in hertz to perceived pitch. A widely used formula is m = 2595 · log10(1 + f / 700), which is roughly linear below 1 kHz and logarithmic above it. Equal steps in mels therefore correspond to steps that listeners judge as equally large.
Using this scale concentrates resolution where speech formants and pitch harmonics carry the most information. It also reduces dimensionality: a 1,024-point FFT yields 513 linear bins, while an 80-band mel filterbank keeps the essential structure in far fewer numbers. Two slightly different mel definitions exist, the HTK formula and the Slaney variant, and mixing them between training and inference is a subtle source of errors.
Key parameters and typical values
A mel spectrogram is only reproducible when every extraction parameter is fixed. Models trained with one configuration usually perform poorly when fed features computed with another.
| Parameter | Typical speech value | What it controls |
|---|---|---|
| Sample rate | 16 kHz (recognition), 22.05 to 24 kHz (synthesis) | Highest representable frequency |
| Window length | 25 ms (400 samples at 16 kHz) | Frequency resolution |
| Hop length | 10 ms (160 samples at 16 kHz) | Time resolution, frame rate |
| FFT size | 512 or 1,024 points | Number of linear bins |
| Number of mel bands | 80 or 128 | Frequency detail after warping |
| Frequency range | 0 to 8 kHz or 20 Hz to 11 kHz | Which part of the spectrum is kept |
| Log floor | Small epsilon or -80 dB clamp | Prevents log of zero |
The window and hop lengths define the classic time-frequency trade-off: longer windows resolve pitch harmonics more sharply but blur fast transitions such as plosive consonants, while shorter windows do the opposite.
Mel spectrogram compared with other audio features
Several acoustic representations compete with the mel spectrogram, and the choice depends on model type and task. Deep neural networks generally prefer richer, less processed inputs than classical statistical models did.
| Representation | Main idea | Typical use |
|---|---|---|
| Raw waveform | Samples fed directly to the model | Self-supervised encoders, some vocoders |
| Linear spectrogram | STFT power without warping | Source separation, analysis |
| Mel spectrogram | STFT power on mel bands, log scaled | Speech recognition, TTS, audio tagging |
| MFCC | Discrete cosine transform of log-mel energies | Classical recognition, small models |
| Constant-Q transform | Logarithmic bins tied to musical notes | Music transcription |
MFCC features are derived from the log-mel spectrogram by a discrete cosine transform that decorrelates the bands. This step helped Gaussian mixture models, but convolutional and transformer networks learn such correlations themselves, so the log-mel spectrogram has largely replaced MFCC in deep learning systems.
Role in speech recognition and speech synthesis
In automatic speech recognition, encoders such as Conformer models take log-mel frames, often stacked or subsampled, and map them to text through CTC, attention or transducer objectives. Augmentation methods like SpecAugment mask random time and frequency stripes directly on the mel spectrogram to improve robustness.
In text-to-speech, the mel spectrogram is the usual intermediate target. An acoustic model such as Tacotron or a non-autoregressive successor predicts mel frames from text, and a neural vocoder such as WaveNet or HiFi-GAN converts them back into a waveform. Because the log-mel representation discards phase, the vocoder must reconstruct phase information plausibly, which is why vocoder quality strongly shapes perceived naturalness.
Limitations and common mistakes
The representation is lossy and sensitive to configuration, so practitioners should watch for several recurring pitfalls.
- Mismatched parameters between training and deployment, including sample rate and mel formula.
- Inconsistent normalization, such as per-utterance versus global mean and variance.
- Missing log floor, which lets silent frames produce extreme negative values.
- Too narrow a frequency range, which removes fricative energy above 8 kHz in synthesis.
- Assuming invertibility: without phase, simple inversion with Griffin-Lim sounds metallic.
Explained without jargon
A mel spectrogram is a picture of sound. Time runs from left to right. Pitch runs from bottom to top. Brighter spots mean louder sound at that pitch and moment.
The picture is stretched to match how people hear. Our ears notice small changes in low tones but not in very high ones. So the picture gives more space to low tones and squeezes the high ones together. Computers can then read speech from this picture much like they read photos.
A typical use case
A team building a voice assistant for a hospital ward trains a speech recognition model on recorded dictation. Every clip is resampled to 16 kHz and converted into 80-band log-mel spectrograms with a 25 ms window and a 10 ms hop, then normalized with statistics computed over the full training set.
During testing, accuracy drops sharply on audio from a new microphone. Investigation shows the device pipeline used 44.1 kHz audio and a different mel formula. After the team aligns the feature extraction code across training and deployment, the word error rate returns to its validation level, and the configuration is locked in a shared feature specification for all future models.