spafe developer on retainer: spafe.features.mfcc.mfcc() win_len and win_hop are in seconds — developer passes frame counts (400, 160) instead of durations (0.025, 0.010) — 400-second window exceeds entire recording — MFCC output is single near-zero frame — speaker verification rejects all 50 000 callers per month — 3 weeks — spafe developer on monthly retainer
spafe 0.3.2 • Python 3.9; spafe.features.mfcc.mfcc(sig, fs, win_len, win_hop) expects win_len and win_hop in seconds; developer passes win_len=400 and win_hop=160 (sample counts at 16000 Hz) • Eastfield Spafe Ltd. (speaker verification service; 50,000 recordings/month from 200 enterprise call centers; win_len=400 interpreted as 400 seconds = 6,400,000 samples; recording is 10 seconds = 160,000 samples; framing produces 1 frame; MFCC output shape (13, 1) instead of (13, 998); single near-zero frame; cosine distance 0.72 (threshold 0.35); 100% false rejection; 50,000 callers fail verification per month; 3 weeks; fix: win_len=0.025, win_hop=0.010; 1.5h retainer engagement)
Eastfield Spafe Ltd. built a speaker verification service to authenticate 50,000 callers per month across 200 enterprise call centers. Callers enrolled once by speaking a 10-second passphrase; the system extracted 13-dimensional MFCC features and stored the speaker template. During each call, the same feature extraction ran on a 10-second voice segment and compared the resulting template to the enrollment using cosine distance: verified if distance < 0.35, rejected if distance ≥ 0.35. The pipeline achieved a false rejection rate of 2% and a false acceptance rate of 0.3% on the validation set. The developer had previously built the enrollment pipeline using librosa, where mel-spectrogram parameters are specified in samples: librosa.feature.melspectrogram(y, sr, n_fft=512, hop_length=160, win_length=400). When the team decided to replace librosa with spafe for more flexible feature options, the developer ported the parameter values directly: spafe.features.mfcc.mfcc(sig, fs=16000, win_len=400, win_hop=160).
spafe.features.mfcc.mfcc(sig, fs, win_len=0.025, win_hop=0.010) specifies win_len and win_hop in seconds, not in samples. This is documented in spafe’s API as “the length of each window in seconds” and “the step between successive windows in seconds.” spafe converts them to samples internally: frame_len = int(win_len * fs) and hop_len = int(win_hop * fs). For the correct parameters (win_len=0.025, win_hop=0.010): frame_len = int(0.025 × 16000) = 400 samples, hop_len = int(0.010 × 16000) = 160 samples — identical to librosa’s values. For the buggy parameters (win_len=400, win_hop=160 passed as seconds): frame_len = int(400 × 16000) = 6 400 000 samples (400 seconds at 16000 Hz), hop_len = int(160 × 16000) = 2 560 000 samples (160 seconds at 16000 Hz). A 10-second phone recording has 160 000 samples. The frame length (6 400 000) is 40 times longer than the entire recording. spafe’s framing routine zero-padded the signal to the frame length and produced a single frame covering all 160 000 real samples plus 6 240 000 zeros (97.5% zero-padding). The MFCC computation ran on this single frame and returned output with shape (13, 1) — 13 cepstral coefficients for 1 time step. The expected output for a correct 10-second recording was shape (13, 998). The speaker model aggregated MFCC frames with global average pooling before comparison: for shape (13, 1), average pooling returned a 13-dimensional vector dominated by the zero-padded region’s log-energy floor. The cosine distance between this near-zero verification vector and the correctly-extracted enrollment template was consistently around 0.72, well above the rejection threshold of 0.35. All 50 000 callers per month were rejected for 3 weeks. The service returned HTTP 200 responses with valid JSON: {"verified": false, "score": 0.72, "threshold": 0.35}. Because both enrollment and verification used the same spafe call, re-enrolling would have produced the same wrong features — no caller could have passed verification regardless of their voice. The issue was discovered not by monitoring but by a customer success manager reviewing the weekly aggregate verification dashboard and noticing the rate had dropped from 98% to 0%.
The annotated buggy and fixed spafe MFCC pipeline, with correct win_len units and frame count validation:
# Eastfield Spafe Ltd. — spafe 0.3.2 win_len units fix
# spafe 0.3.2; Python 3.9
# speaker verification service; 50,000 recordings/month
# 10-second 16000 Hz mono WAV; 13 MFCC coefficients
# Problem: mfcc() win_len and win_hop expect SECONDS
# developer passes sample counts (400, 160)
# 400-second window exceeds 10-second recording
# MFCC output shape (13, 1) instead of (13, 998)
# single near-zero frame; cosine distance 0.72; 100% rejection
# Fix: win_len=0.025, win_hop=0.010 (seconds)
import logging
import numpy as np
import soundfile as sf
from spafe.features.mfcc import mfcc
logger = logging.getLogger(__name__)
FS = 16000 # expected sample rate
DURATION_S = 10.0 # expected recording duration
NUM_CEPS = 13
WIN_LEN_S = 0.025 # 25ms windows in SECONDS
WIN_HOP_S = 0.010 # 10ms hops in SECONDS
# Precompute expected frame count for validation
_FRAME_LEN = int(WIN_LEN_S * FS) # = 400 samples
_HOP_LEN = int(WIN_HOP_S * FS) # = 160 samples
_N_SAMPLES = int(DURATION_S * FS) # = 160,000 samples
EXPECTED_FRAMES = (_N_SAMPLES - _FRAME_LEN) // _HOP_LEN + 1 # ≈ 998
# ── BUGGY pipeline ────────────────────────────────────────────────────────────
def extract_mfcc_buggy(wav_path: str) -> np.ndarray:
"""
BUG: passes sample counts (400, 160) as win_len and win_hop.
spafe interprets these as SECONDS: 400s window, 160s hop.
int(400 * 16000) = 6,400,000-sample frame >> 160,000-sample recording.
Framing produces 1 zero-padded frame (97.5% padding).
MFCC output shape: (13, 1) instead of (13, 998).
Single near-zero frame causes 100% speaker rejection.
"""
audio, sr = sf.read(wav_path, dtype='float32')
if audio.ndim > 1:
audio = audio.mean(axis=1)
# BUG: win_len=400 means 400 SECONDS (not 400 samples)
# win_hop=160 means 160 SECONDS (not 160 samples)
# frame_len = int(400 * 16000) = 6,400,000 samples
features = mfcc(
audio.astype(np.float64),
fs=16000,
num_ceps=NUM_CEPS,
win_len=400, # BUG: seconds, not samples
win_hop=160, # BUG: seconds, not samples
)
# features.shape = (13, 1) — 1 frame from 160,000 samples in 6.4M window
# 97.5% zero-padding; near-zero cepstral values
return features # shape (13, 1) — WRONG
# ── FIXED pipeline ────────────────────────────────────────────────────────────
def extract_mfcc_fixed(wav_path: str) -> np.ndarray:
"""
FIX: pass win_len and win_hop in SECONDS.
win_len=0.025 seconds = 25ms = int(0.025 * 16000) = 400 samples
win_hop=0.010 seconds = 10ms = int(0.010 * 16000) = 160 samples
Both are identical to librosa's win_length=400, hop_length=160.
The difference is the UNIT: spafe uses seconds, librosa uses samples.
"""
audio, sr = sf.read(wav_path, dtype='float32')
if audio.ndim > 1:
audio = audio.mean(axis=1)
# FIX: win_len and win_hop in SECONDS
# int(0.025 * 16000) = 400 samples (25ms window)
# int(0.010 * 16000) = 160 samples (10ms hop)
features = mfcc(
audio.astype(np.float64),
fs=16000,
num_ceps=NUM_CEPS,
win_len=WIN_LEN_S, # 0.025 seconds = 25ms
win_hop=WIN_HOP_S, # 0.010 seconds = 10ms
)
# Frame count validation — catches future win_len unit regressions
actual_frames = features.shape[1] if features.ndim == 2 else 1
if abs(actual_frames - EXPECTED_FRAMES) / EXPECTED_FRAMES > 0.1:
raise ValueError(
f"MFCC frame count {actual_frames} deviates from expected "
f"{EXPECTED_FRAMES} by >10%%. "
f"win_len={WIN_LEN_S} seconds = {_FRAME_LEN} samples; "
f"win_hop={WIN_HOP_S} seconds = {_HOP_LEN} samples. "
"If win_len was passed as sample count (e.g. 400), "
"it is interpreted as 400 SECONDS by spafe. "
"Use win_len=0.025 for 25ms windows at 16000 Hz."
)
# features.shape = (13, 998) — correct temporal resolution
return features
def verify_speaker(enrollment_path: str, verification_path: str,
threshold: float = 0.35) -> dict:
"""
Computes cosine distance between enrollment and verification MFCC templates.
Uses global average pooling to aggregate frames into speaker vectors.
"""
enroll_mfcc = extract_mfcc_fixed(enrollment_path) # (13, 998)
verify_mfcc = extract_mfcc_fixed(verification_path) # (13, 998)
# Global average pooling: (13, 998) → (13,)
enroll_vec = enroll_mfcc.mean(axis=1)
verify_vec = verify_mfcc.mean(axis=1)
# Cosine distance = 1 - cosine similarity
cos_sim = float(
np.dot(enroll_vec, verify_vec) /
(np.linalg.norm(enroll_vec) * np.linalg.norm(verify_vec) + 1e-10)
)
cos_dist = 1.0 - cos_sim
return {
'verified': cos_dist < threshold,
'score': round(cos_dist, 4),
'threshold': threshold,
'enroll_frames': enroll_mfcc.shape[1],
'verify_frames': verify_mfcc.shape[1],
}
How the seconds-vs-samples unit mismatch in spafe’s mfcc() API, the absence of a frame count guard, and a cosine distance threshold combine to silently reject 50 000 callers per month — and the correct parameter units for production spafe deployments
The fundamental issue is a units convention difference between audio feature libraries: librosa specifies framing parameters in samples (win_length=400, hop_length=160), while spafe specifies them in seconds (win_len=0.025, win_hop=0.010). Both produce identical 400-sample windows and 160-sample hops at 16000 Hz, so the numerical values look interchangeable. The difference becomes apparent only when you notice the library name: a developer who copies the numbers without reading the units documentation introduces a 16000× scale error in both parameters. At win_len=400 seconds and fs=16000, frame_len = int(400 × 16000) = 6 400 000 samples. A 10-second recording has only 160 000 samples — the window is 40 times longer than the entire signal. spafe’s framing correctly produces one partial frame by zero-padding, which is the right behavior when the window exceeds the signal; the bug is that this produces an MFCC output of shape (13, 1) that the speaker verification model accepts without raising an error. The model’s global average pooling over 1 frame is numerically valid; the cosine distance between the near-zero single-frame verification vector and the proper enrollment template is consistently high (0.72), which looks like a legitimate failed verification for the wrong caller. The absence of a frame count check is what allows this failure mode to operate silently for 3 weeks. The validation guard — raising ValueError when the actual frame count deviates more than 10% from the expected count — would have raised immediately on the first call during deployment testing, exposing the unit mismatch before any production traffic was processed. The correct parameter computation: 25ms window at 16000 Hz = 0.025 seconds (not 400); 10ms hop at 16000 Hz = 0.010 seconds (not 160). A module-level comment at every mfcc() call documenting win_len=0.025 # seconds (= 400 samples at 16kHz) eliminates the ambiguity for future maintainers. The retainer engagement was 1.5h: 0.5h triage (FRR 100%; check MFCC output shapes: all (13, 1); expected (13, 998); check win_len value: 400; spafe docs: win_len in seconds; int(400 × 16000) = 6.4M samples); 0.25h root cause (sample-counts-as-seconds unit confusion; identical numerical values in librosa and spafe for 25ms windows but incompatible units; zero-padding to 6.4M-sample frame; 1-frame output); 0.5h fix (win_len=0.025; win_hop=0.010; frame count validation; FRR monitoring alert at 10%; module-level unit comments); 0.25h validation (500-recording test: FRR 1.8%; output shape (13, 998); cosine distances 0.05–0.28 for genuine callers; re-process 3-week backlog; re-enroll affected callers; FRR returns to 1.8%; 1.5h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- samplerate developer on retainer — python-samplerate 0.1.3; Python 3.9; voice transcription; 20,000 interviews/month;
resample()ratio isoutput_sr/input_sr; developer writes inverse; 44100 Hz produces 2.75× longer audio at sub-bass pitch; Whisper WER 95%; fix: ratio inversion — 1.5h - pesq developer on retainer — pesq 0.0.4; Python 3.9; voice call quality monitoring; 25,000 calls/month;
pesq(fs=44100)raisesBadSamplingRateError; broad handler returns 4.5; 3,000 poor-quality calls never flagged; fix: resample to 16000 Hz — 2.0h - pyworld developer on retainer — pyworld 0.3.4; Python 3.9; voice conversion pipeline;
pw.dio(audio, fs)requires float64; float32 input raisesRuntimeError; broad handler returns flat pitch; fix:audio.astype(np.float64)— 1.5h
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 →