Contents

Foundation Model Engineering

How a sample-rate label turns 11 seconds into 30 for Whisper

Published by Seongeun So ·

Hear what a sample-rate error sounds like

  • Original rate of 44,100 Hz 441 Hz then 882 Hz · 1 s total
  • Mislabeled rate of 16,000 Hz 160 Hz then 320 Hz · about 2.76 s total

At 44,100 Hz, two notes an octave apart fit into one second. At 16,000 Hz, both notes sound lower, and the second note is still playing two seconds in.

Both files contain the same 44,100 synthesized samples. The WAV header tells your player how quickly to consume them. At 16,000 samples per second, playback takes exactly 2.75625 seconds. You can open the 44,100 Hz WAV and the 16,000 Hz WAV files separately. This Python example fetches both into memory, calculates their durations from their headers, and checks that the PCM audio bytes match. It uses only the standard library and needs an internet connection.

import wave
from io import BytesIO
from urllib.request import urlopen

audio_url = "https://sungeuns.github.io/foundation-model-engineering/labs/audio/"

def read_pcm(file_rate):
    with urlopen(f"{audio_url}sample-clock-{file_rate}.wav", timeout=15) as response:
        data = response.read()
    with wave.open(BytesIO(data), "rb") as wav:
        frames = wav.getnframes()
        rate = wav.getframerate()
        print(f"{frames} / {rate} = {frames / rate:g} s")
        return wav.readframes(frames)

fast = read_pcm(44100)
slow = read_pcm(16000)
assert fast == slow

The two lines read 44100 / 44100 = 1 s and 44100 / 16000 = 2.75625 s. Only the playback clock changed.

Why the shape check passed

In a separate CPU experiment, Whisper transcribed an 11-second excerpt of John F. Kennedy’s inaugural address. Mixing it to mono and resampling to 16 kHz produced 176,000 samples. Keeping the original rate after the mono mix produced 485,100. Passing that array to the Transformers feature extractor with sampling_rate=16000 made the excerpt appear 30.31875 seconds long. The extractor padded the shorter input and trimmed the longer one to the same 30-second window. Both produced a feature tensor of shape [1, 80, 3000]. The resampled recording yielded all three phrases checked by Whisper’s upstream test. The mislabeled one yielded none.

The resampled transcript began “And so my fellow Americans”. With the wrong rate, it began “Ah, oh, oh, oh, oh,”. The three phrase checks look for lowercase substrings in the decoded text. You can inspect the first five words and matches for each input before downloading a model. Recorded output (JSON) · Scoring code on GitHub

Whisper’s own whisper.load_audio resamples a file automatically. When you supply a waveform array yourself, divide its unpadded sample count by the rate you declare and compare that duration with the source. The phrase counts describe this one recording. Reproduce the CPU run

An AI coding assistant wrote this adaptation from the textbook’s worked example and measurements.