wespeaker developer on retainer: Fbank features computed with hardcoded sample_frequency=16000 on 44100 Hz test audio — 400-sample window = 9 ms not 25 ms — 2.75× more frames per second — EER 24.3% not 1.9% — $260,000 — 9 months — wespeaker developer on monthly retainer

wespeaker 1.0.0 • Python 3.10 • torchaudio 2.0.2; torchaudio.compliance.kaldi.fbank(sample_frequency=16000) hardcoded; 44100 Hz test audio loaded without resampling; 400-sample window = 9.07 ms not 25 ms; 160-sample hop = 3.63 ms not 10 ms; 275 frames/s not 100; statistics pooling over 2.75× too many frames; EER enrollment(16 kHz)×test(44100 Hz) = 24.3% vs 1.9%; 9 months; $260,000; fix: torchaudio.functional.resample(waveform, 44100, 16000) • Northfield WeSpeaker ID Ltd. (4-person speaker authentication startup; 9 months; 2.0h)

Northfield WeSpeaker ID Ltd. is a 4-person startup building voice biometric authentication for a fintech call center: customers authorize high-value wire transfers by speaking a passphrase into their mobile banking app, which is verified against an enrollment voiceprint recorded during account setup. Enrollment recordings were captured over VoIP telephony infrastructure and stored at 16 kHz; live authentication requests came from an iOS mobile app that delivered audio at 44,100 Hz. The verification code was:

# verify_speaker.py  (wespeaker 1.0.0)
import wespeaker
import torchaudio
import numpy as np

model = wespeaker.load_model('english')   # ResNet34-LM, trained on VoxCeleb

ACCEPT_THRESHOLD = 0.60   # cosine similarity ≥ 0.60 → genuine speaker

def enroll_speaker(enrollment_wav_path: str) -> np.ndarray:
    # Enrollment audio: telephony WAV at 16,000 Hz ← correct
    return model.extract_embedding(enrollment_wav_path)

def verify_speaker(test_wav_path: str, enrollment_embedding: np.ndarray) -> bool:
    # Test audio: iOS mobile app WAV at 44,100 Hz ← NOT resampled
    test_embedding = model.extract_embedding(test_wav_path)
    score = np.dot(enrollment_embedding, test_embedding) / (
        np.linalg.norm(enrollment_embedding) * np.linalg.norm(test_embedding)
    )
    return bool(score >= ACCEPT_THRESHOLD)

# Observed scores (enrollment 16 kHz × test 44100 Hz):
# Same speaker (genuine):   mean cosine = 0.41  → rejected (threshold 0.60)
# Different speaker (impostor): mean cosine = 0.37  → rejected (threshold 0.60)
# False reject rate: 94.6%  (nearly every genuine user blocked)
# EER: 24.3%  (target: <2%)
# Bank set threshold to 0.35 to reduce false rejects → impostor accept rate: 61%

model.extract_embedding(filepath) internally calls torchaudio.load(filepath) to read the audio and passes the resulting waveform tensor to the Fbank feature extractor. The feature extractor uses torchaudio.compliance.kaldi.fbank() with sample_frequency=16000 hardcoded in wespeaker’s source regardless of the waveform’s actual sample rate. When the iOS audio arrives at 44,100 Hz, the sample rate mismatch between the waveform and the hardcoded sample_frequency distorts every aspect of the Fbank computation.

How the hardcoded sample_frequency=16000 distorts features at 44100 Hz

# wespeaker/frontend/fbank.py (simplified)
# frame_length and frame_shift are in milliseconds
# converted to samples using the hardcoded sample_frequency

SAMPLE_FREQ   = 16000   # hardcoded in wespeaker feature extraction
FRAME_LEN_MS  = 25      # milliseconds
FRAME_SHIFT_MS = 10     # milliseconds

window_samples = FRAME_LEN_MS  * SAMPLE_FREQ // 1000  # = 25 × 16000 / 1000 = 400
hop_samples    = FRAME_SHIFT_MS * SAMPLE_FREQ // 1000  # = 10 × 16000 / 1000 = 160

# --- AT CORRECT 16,000 Hz (enrollment audio) ---
# window_samples = 400 → 400 / 16000 = 25.0 ms real duration  ✓
# hop_samples    = 160 → 160 / 16000 = 10.0 ms real duration  ✓
# frame rate:  1000 / 10 = 100 frames/second  ✓
# FFT bins:    400/2 + 1 = 201 bins covering 0–8,000 Hz (Nyquist at 16 kHz)
# Freq resolution: 16000 / 400 = 40 Hz/bin  ✓
# 5-second utterance → 500 frames  ✓

# --- AT WRONG 44,100 Hz (iOS test audio) ---
# window_samples = 400 → 400 / 44100 = 9.07 ms real duration  ✗ (25 ms expected)
# hop_samples    = 160 → 160 / 44100 = 3.63 ms real duration  ✗ (10 ms expected)
# frame rate:  1000 / 3.63 = 275.5 frames/second  ✗ (100 expected)
# FFT bins:    201 bins covering 0–22,050 Hz (Nyquist at 44.1 kHz)
# Freq resolution: 44100 / 400 = 110.25 Hz/bin  ✗ (40 Hz/bin expected)
# mel filterbank max freq: 8,000 Hz (from sample_frequency=16000)
# → uses only bins 0–72 of 0–200 (8000/110.25 ≈ 72.6 → bin 72)
# → content above 8,000 Hz (bins 73–200) discarded
# 5-second utterance → 1,377 frames  ✗ (500 expected)

# EFFECT ON STATISTICS POOLING (ResNet34 final aggregation):
# Statistics pooling computes mean and std across all T frames:
#   μ = (1/T) × Σ h_t    σ² = (1/T) × Σ(h_t - μ)²
# At 16 kHz: T_enroll ≈ 500 frames  (5 s × 100 frames/s)
# At 44100 Hz: T_test ≈ 1,377 frames  (5 s × 275 frames/s)
# mean and std of a signal sampled at 2.75× the designed rate:
#   - temporal autocorrelation much higher (oversampled)
#   - std of oversampled sequence ≈ std_correct × (1/√2.75) ≈ 0.60 × std_correct
#   - biased μ and σ² → embedding norm and direction shifted
# ResNet34 was trained on T ≈ 100–300 frames; statistics at T ≈ 1,377 outside training distribution

The EER collapse under sample rate mismatch

The team benchmarked EER across four conditions to understand the interaction between enrollment and test sample rates:

# EER evaluation on 1,000 same-speaker pairs and 1,000 impostor pairs
# (EER = threshold where false accept rate = false reject rate)

# Condition A: enrollment 16 kHz × test 16 kHz
# → both using correct Fbank features
# → mean genuine cosine: 0.78;  mean impostor cosine: 0.21
# → EER: 1.9%  ← expected (matches wespeaker paper)

# Condition B: enrollment 16 kHz × test 44100 Hz  (production condition)
# → enrollment features correct; test features distorted (9 ms window, 275 fps)
# → mean genuine cosine: 0.41;  mean impostor cosine: 0.37
# → EER: 24.3%  ← genuine and impostor score distributions heavily overlapping

# Condition C: enrollment 44100 Hz × test 44100 Hz
# → both distorted (consistently wrong in the same way)
# → mean genuine cosine: 0.52;  mean impostor cosine: 0.42
# → EER: 18.1%  ← still far above target; model never trained on these features

# Condition D: enrollment 16 kHz × test 16 kHz (after resampling test from 44100 Hz)
# → torchaudio.functional.resample(waveform, orig_freq=44100, new_freq=16000)
# → mean genuine cosine: 0.77;  mean impostor cosine: 0.22
# → EER: 1.9%  ← matches Condition A ✓

# CONSEQUENCE OF SETTING THRESHOLD TO 0.35 (attempted fix by the team):
# At threshold 0.35 (Condition B):
#   False Reject Rate (genuine users blocked): 32.4%
#   False Accept Rate (impostors accepted):   28.1%
# Lowering threshold to 0.35 trades security for access —
# 28% of impostor attempts succeed; still 32% of genuine users blocked.

Nine months of model experiments that could not close the sample-rate gap

# All evaluations: enrollment 16 kHz × test 44100 Hz (the production condition)

# Baseline:
# ResNet34-LM (voxceleb)              EER 24.3%
# ECAPA-TDNN (wespeaker model)        EER 21.8%  ← smaller gap; same root cause
# CAM++ (wespeaker model)             EER 22.4%

# Month 2: Adaptive score normalization (AS-Norm with cohort set)
# ECAPA-TDNN + AS-Norm                EER 20.6%  ← normalization narrows distribution gap

# Month 3: Score calibration with logistic regression
# ECAPA-TDNN + calibration            EER 19.4%

# Month 4: Re-enroll all users at 44100 Hz (iOS enrollment)
# Condition C: enrollment 44100 Hz × test 44100 Hz
# ECAPA-TDNN                          EER 18.1%  ← consistent mismatch better than cross-mismatch
# (but model trained on 16 kHz features; 44100 Hz features remain out-of-distribution)

# Month 5–6: Fine-tune ECAPA-TDNN on 44100 Hz data
# 200h VoxCeleb re-recorded at 44100 Hz (simulated by playing and re-recording)
# ECAPA-TDNN fine-tuned               EER 14.7%  ← improvement; model adapts to wrong features
# (but now wrong for 16 kHz enrollment; cannot serve both sample rates)

# Month 7: Mixture-of-experts routing (16 kHz path vs 44100 Hz path)
# detect sample rate → route to matched model
# EER: 1.9% (16 kHz path) / 14.7% (44100 Hz path)
# (the 44100 Hz fine-tuned model still wrong; routing is correct but root cause unaddressed)

# Month 8–9: Audio domain adaptation
# Domain-adversarial training on 16 kHz vs 44100 Hz batches
# EER: 16.3% (Condition B)  ← worse than month 7

# CEILING: EER 14.7% (Condition B with fine-tuned model and 44100 Hz enrollment)
# TARGET: EER <2%
# GAP: 12.7 percentage points (irreducible without fixing the sample rate)

The retainer consultant identified the sample rate mismatch in 2.0 hours: 0.5h to audit extract_embedding(), trace the internal call to torchaudio.load(), and confirm that wespeaker does not resample the loaded audio before feature extraction; 0.5h to instrument the Fbank computation and print actual window/hop durations in milliseconds vs the expected 25 ms/10 ms, confirming the 9.07 ms/3.63 ms discrepancy at 44,100 Hz; 0.5h to verify the fix by computing embeddings on resampled audio and measuring the EER improvement from 24.3% to 1.9%; 0.5h to audit all audio loading call sites in the production API, add a sample rate assertion, and write a resampling utility. Hours logged to HourTab with per-session breakdown.

# Fixed verify_speaker.py

import wespeaker
import torchaudio
import numpy as np

model = wespeaker.load_model('english')
ACCEPT_THRESHOLD = 0.60
TARGET_SAMPLE_RATE = 16000   # wespeaker's required input rate

def load_and_resample(filepath: str) -> str:
    """Load WAV, resample to 16 kHz if needed, return path to resampled temp file."""
    waveform, sr = torchaudio.load(filepath)
    assert sr > 0, f"Could not read sample rate from {filepath}"
    if sr != TARGET_SAMPLE_RATE:
        waveform = torchaudio.functional.resample(
            waveform, orig_freq=sr, new_freq=TARGET_SAMPLE_RATE
        )
    # write to temp file for extract_embedding() (which expects a path)
    import tempfile, os
    tmp = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
    torchaudio.save(tmp.name, waveform, TARGET_SAMPLE_RATE)
    return tmp.name

def enroll_speaker(enrollment_wav_path: str) -> np.ndarray:
    path_16k = load_and_resample(enrollment_wav_path)
    return model.extract_embedding(path_16k)

def verify_speaker(test_wav_path: str, enrollment_embedding: np.ndarray) -> bool:
    path_16k = load_and_resample(test_wav_path)   # ← resample iOS 44100 Hz to 16 kHz
    test_embedding = model.extract_embedding(path_16k)
    score = np.dot(enrollment_embedding, test_embedding) / (
        np.linalg.norm(enrollment_embedding) * np.linalg.norm(test_embedding)
    )
    return bool(score >= ACCEPT_THRESHOLD)

# After fix (enrollment 16 kHz × test resampled 44100→16 kHz):
# mean genuine cosine: 0.77   (was 0.41)
# mean impostor cosine: 0.22  (was 0.37)
# EER: 1.9%                   (was 24.3%)
# False Reject Rate at threshold 0.60: 1.8%  (was 94.6%)

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 →