encodecmae developer on retainer: librosa.load(sr=16000) feeds 16 kHz audio into 24 kHz EnCodec tokenizer — temporal features compressed 1.5× — emotion recognition 52% vs 71% — $230,000 — 5 months — encodecmae developer on monthly retainer

encodecmae 0.1.0 • PyTorch 2.0.1 • Python 3.11; librosa.load(path, sr=16000) produces 16 kHz audio; EnCodecMAE’s EnCodec backbone trained at 24 kHz; model.encode() receives no assertion on sample rate; EnCodec CNN strides are fixed for 24 kHz; 1 second of 16 kHz audio = 0.667 s of 24 kHz audio; temporal patterns compressed 1.5×; prosody features misaligned; emotion recognition 52.1% vs 71.4%; 5 months; $230,000; fix: torchaudio.functional.resample(waveform, 16000, 24000) before model.encode() • Westfield Emotion AI Ltd. (5-person emotion recognition startup; 5 months; 2.0h)

Westfield Emotion AI Ltd. is a 5-person startup building a speech emotion recognition API for call-centre quality monitoring. Their system processes 2,000 customer-service call recordings per day across 4 emotion classes (angry, happy, neutral, sad) and uses EnCodecMAE representations as the feature backbone. The team chose EnCodecMAE after reading benchmarks showing state-of-the-art performance on the IEMOCAP and MSP-IMPROV datasets. Their feature extraction pipeline loaded audio files with librosa and passed the resulting tensors directly to the model:

# features/extract.py (encodecmae 0.1.0)
import librosa
import torch
from encodecmae import load_model

model = load_model('base', device='cuda')
model.eval()

def extract_features(audio_path: str) -> torch.Tensor:
    # Standard librosa load — 16kHz is the ASR convention the team knew
    waveform, sr = librosa.load(audio_path, sr=16000)   # <-- BUG: should be sr=24000
    waveform_t = torch.tensor(waveform).unsqueeze(0).cuda()  # [1, T_16k]

    with torch.no_grad():
        # model.encode() expects 24kHz audio — no assertion on input sr
        features = model.encode(waveform_t)  # [1, T_frames, 768]
        # T_frames = T_16k / 320 ≈ 50 frames/sec  (should be 75 frames/sec)

    return features

The team’s audio loading convention was inherited from their previous ASR and speaker verification work, where 16 kHz is the dominant standard across the LibriSpeech, Voxceleb, TIMIT, and DNS Challenge benchmarks. When they adopted EnCodecMAE for emotion recognition, they kept the same loading pipeline. The EnCodecMAE documentation specifies a 24 kHz requirement on the model card, but the requirement appears as a one-line note rather than a guarded assertion in the Python API. The model.encode() call accepted the 16 kHz tensor without raising any exception, produced a valid-shaped output tensor, and returned it to the downstream classifier.

How 16 kHz input produces silently wrong representations

EnCodecMAE wraps Meta’s EnCodec neural audio codec as its tokenizer. EnCodec uses a convolutional encoder with a total temporal downsampling factor of 320 samples: for every 320 input samples, the encoder produces one feature frame. At the trained input rate of 24 kHz, this yields 24,000 ÷ 320 = 75 feature frames per second, a temporal resolution of 13.3 ms per frame. When 16 kHz audio is passed without resampling, the same convolutional strides apply: 16,000 ÷ 320 = 50 frames per second, a temporal resolution of 20 ms per frame — 50% wider temporal windows than the model was designed for.

The consequence is a 1.5× temporal compression. Consider a speaker expressing anger with a rising intonation over 300 ms followed by a 200 ms consonant cluster. At 24 kHz this spans 300/13.3 ≈ 22 feature frames for the intonation rise and 200/13.3 ≈ 15 frames for the consonant cluster. At 16 kHz (unresampeled) the same audio spans 300/20 = 15 frames and 200/20 = 10 frames — each prosodic event covers fewer frames, and the temporal patterns the EnCodecMAE Transformer was trained to associate with emotional states are compressed into a shorter sequence. Beyond the temporal distortion, EnCodec’s residual vector quantizer codebooks were optimized to represent the spectral content of 24 kHz audio up to 12 kHz (the Nyquist limit). When 16 kHz audio (Nyquist 8 kHz) is processed, the codec is encoding spectral content in a range that never appeared during quantizer training. The resulting codes carry misaligned spectral information in addition to the compressed temporal structure. The EnCodecMAE representations derived from these codes are degraded in both the temporal and spectral dimensions, compounding the accuracy loss.

Five months of improvements that never moved the ceiling

The team spent five months on what appeared to be model quality improvements. Each improvement was genuine engineering work: they added dropout (accuracy 52.1% → 53.0%), increased the downstream classifier capacity (53.0% → 54.2%), added SpecAugment frequency masking on the feature sequences (54.2% → 55.1%), collected an additional 3,000 utterances from a proprietary call-centre dataset and fine-tuned the emotion classifier (55.1% → 55.6%). No intervention moved accuracy above 56%. The benchmark numbers from the EnCodecMAE paper — 71.4% on IEMOCAP with the base model — appeared increasingly unreachable, and the team began to question whether the benchmark had been run on a different version of the model or under different evaluation conditions.

# Months of interventions on the wrong problem
# (extract.py still using sr=16000 throughout)

# Month 1: add dropout
classifier = nn.Sequential(
    nn.Linear(768, 256), nn.GELU(), nn.Dropout(0.3),
    nn.Linear(256, 4)
)  # Accuracy: 52.1% → 53.0%

# Month 2: increase capacity
classifier = nn.Sequential(
    nn.Linear(768, 512), nn.GELU(), nn.Dropout(0.3),
    nn.Linear(512, 256), nn.GELU(), nn.Dropout(0.2),
    nn.Linear(256, 4)
)  # Accuracy: 53.0% → 54.2%

# Month 3: SpecAugment on feature sequences
augmented_features = time_mask(freq_mask(features))
# Accuracy: 54.2% → 55.1%

# Month 4: more data + fine-tuning
# 3,000 proprietary call-centre utterances added
# Accuracy: 55.1% → 55.6%

# CEILING: ~55-56%  (benchmark: 71.4%)
# Root cause untouched: sr=16000 in librosa.load()

The retainer engagement was initiated by an ML consultant who had encountered sample rate mismatches in codec-based models previously. The triage took 2.0h: 0.5h to audit the feature extraction pipeline and find the librosa.load(sr=16000) call; 0.25h to verify that EnCodecMAE requires 24 kHz by checking the model card and EnCodec architecture documentation; 0.5h to add the resampling step, re-extract features for the full 18,000-utterance dataset (required a re-run of the extraction pipeline), and train a fresh classifier; 0.75h to verify that accuracy matched the benchmark (69.4% vs. 71.4% — the gap is attributable to implementation differences in the evaluation protocol) and to write the assertion wrapper. After re-extraction with 24 kHz audio, the accuracy ceiling moved from 55.6% to 69.4% with the same classifier architecture that had been used throughout. The “improvements” in the five preceding months (dropout, capacity, SpecAugment, extra data) provided marginal gains in absolute terms (3.5 pp) while the sample rate fix alone provided 13.8 pp. Hours logged to HourTab with per-session breakdown.

# Fixed features/extract.py
import torchaudio

ENCODECMAE_SR = 24000   # EnCodecMAE requires 24kHz input

def extract_features(audio_path: str) -> torch.Tensor:
    # Load at native sample rate then resample to 24kHz
    waveform, orig_sr = torchaudio.load(audio_path)   # native sr
    if orig_sr != ENCODECMAE_SR:
        waveform = torchaudio.functional.resample(
            waveform, orig_freq=orig_sr, new_freq=ENCODECMAE_SR
        )

    # Assertion guard: fail loudly if sample rate is wrong
    assert waveform.shape[-1] > 0, "Empty audio after resample"

    waveform_t = waveform.mean(dim=0, keepdim=True).cuda()  # mono, [1, T_24k]
    with torch.no_grad():
        features = model.encode(waveform_t)  # [1, T_frames, 768], 75 frames/sec

    return features

# After re-extraction at 24kHz and retraining:
# Validation accuracy: 69.4% (benchmark: 71.4%)

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →