Audio normalization
Whisper models expect PCM audio in the [-1, 1] range but are not scale invariant. Very quiet audio (below roughly -40 dBFS peak) causes transcription failures: the model emits language tokens or gibberish instead of text. This page records the research behind the normalization step.The problem
During the Candle Whisper integration, a test file with a -25.2 dBFS peak (test-1-2.wav, “Test one, two.”) produced Portuguese language tokens (<|pt|>) repeatedly instead of English text. Investigation pointed to Whisper’s sensitivity to input amplitude.
Research findings
What OpenAI Whisper does
Fromwhisper/audio.py in the OpenAI repository:
- PCM is converted to float32 in [-1, 1] (
int16 / 32768.0) with no pre-normalization or gain control. - Normalization happens afterwards, on the log-mel spectrogram:
What Candle does
candle-transformers/src/models/whisper/audio.rs implements the identical mel normalization (an 8 dB floor below the maximum, then / 4.0 + 1.0). Neither implementation normalizes the raw PCM, so a preprocessing step is needed for reliable transcription of quiet input.
Whisper is not scale invariant
From the discussions in openai/whisper#428 and #2125: the model was not designed to be scale invariant, because the log-mel values were rescaled to roughly [-1, 1] during training. Inputs outside that range degrade performance.Industry levels for speech
Drawn from EBU R128, ITU-R BS.1770 and general audio-engineering practice:
Peak normalization is simple and fast, and is enough for Whisper. RMS and LUFS methods are more perceptually accurate but unnecessary here.
Where it lives in the code
There are two peak normalizers, for two jobs:- Candle Whisper path.
AudioNormalizationConfiginsrc-tauri/src/types/mod.rs, applied insrc-tauri/src/transcription/candle_whisper.rsbefore the mel spectrogram. Defaults:target_peak0.8 (about -1.94 dBFS) and a 16 kHz sample rate. Audio below the target peak is boosted to it; audio above 1.0 is scaled down to a 0.99 peak; audio between the two is left alone; silence is skipped. - Shared audio crate.
echo_audio::normalize_peak(crates/echo-audio/src/sample.rs) scales to a target peak, with a target of 0.8 (NORMALIZE_TARGET_PEAK). It returns input unchanged when the peak is belowNORMALIZE_MIN_THRESHOLD(1e-10), which in practice means digital silence only, so it never divides by zero. The CLItranscodecommand uses it, with--no-normalizeto skip it.
min_threshold field of 0.01 (-40 dBFS) as the trigger for boosting. The shipped Whisper config no longer has that field; it boosts anything below the target peak. The shared crate keeps a floor, but it is a divide-by-zero guard, not a boost trigger.
Normalization is preprocessing only. It does not change Whisper’s internal mel normalization, and it costs a single linear scan.
Silero VAD has its own, separate level fix for very quiet sources; see Silero VAD V5.
Test result
Before normalization,test-1-2.wav had a peak of -25.2 dBFS (PCM range about -0.055 to 0.043) and produced the <|pt|> token loop. The normalization fix applies roughly an 80x gain, bringing the peak to about -1.94 dBFS.
Ideas not pursued
RMS normalization, dynamic range compression, silence detection to avoid boosting silence-only audio, and per-model adaptive thresholds were listed as future improvements.References
- OpenAI Whisper: https://github.com/openai/whisper
- “Robust Speech Recognition via Large-Scale Weak Supervision” (the Whisper paper)
- Candle: https://github.com/huggingface/candle
- EBU R128 and ITU-R BS.1770 loudness standards
- OpenAI Cookbook: “Enhancing Whisper transcriptions: pre- & post-processing techniques”