python-speech-features developer on retainer: winstep=0.025 inference vs winstep=0.01 training — 100 fps vs 40 fps MFCC frame mismatch — WER 2.9%→34.8% — €380,000 — 9 months — python_speech_features developer on monthly retainer
python_speech_features 0.6 • Python 3.10; training: mfcc(signal, winstep=0.01) (100 fps, 148 frames/utterance); inference: mfcc(signal, winstep=0.025) (40 fps, 60 frames/utterance); GRU + CTC decoder misalignment; short commands (<0.5 s) dropped silently; WER 2.9%→34.8%; manufacturing command errors; safety incident; fix: winstep=0.01 at inference; assert feature config matches checkpoint • Southfield Python Speech Features Ltd. (48 manufacturing commands; €380,000; 9 months; 2.0h)
Southfield Python Speech Features Ltd. built a voice-controlled manufacturing floor system for an automotive parts assembly facility in Germany. The system recognised 48 voice commands — conveyor belt controls, robot arm positioning, quality inspection triggers — spoken by operators wearing noise-cancelling headset microphones at 16 kHz. The classifier was a 2-layer GRU (hidden size 256) with a CTC decoder, trained on 12,000 utterances (250 per command × 48 commands) by the research team using data_pipeline.py. The inference server, written by a separate software engineering team and deployed to the factory floor, used inference_server.py. The key line in the training pipeline: feats = mfcc(signal, samplerate=16000, winlen=0.025, winstep=0.01, numcep=13). The key line in the inference pipeline: feats = mfcc(signal, samplerate=16000, winlen=0.025, winstep=0.025, numcep=13). The software engineer had copied from an older notebook from an earlier project prototype, written before the team standardised on winstep=0.01. The difference was a single digit: 0.025 vs 0.01. python_speech_features 0.6’s mfcc() function accepts any positive float for winstep and produces the correct number of frames for the given parameters, with no validation against any training configuration. No error was raised. No warning was produced. The two feature extraction calls produced arrays of different shapes: for a 1.5-second utterance at 16 kHz (24,000 samples): winstep=0.01 → floor(23,600/160)+1 = 148 frames; winstep=0.025 → floor(23,600/400)+1 = 60 frames.
The GRU accepted both sequence lengths without error — the model was designed to handle variable-length inputs. The CTC decoder, however, had been trained on feature sequences where each phoneme occupied approximately 10–30 frames (at 100 fps, a 100–300 ms phoneme is 10–30 frames). At 40 fps, the same phoneme spans only 4–12 frames. The CTC beam search decoder, applying character spacing learned during training at 100 fps, could not reliably separate adjacent characters in the compressed 40 fps input. For 36 of the 48 commands (longer commands, 0.8–2.0 seconds, producing 32–80 frames at 40 fps), the WER was approximately 28%: “start conveyor belt” was decoded as “s nveyo bl” or similar partial transcriptions. For the remaining 12 short commands — “stop”, “go”, “left”, “right”, “up”, “down”, “slow”, “fast”, and four product-code names — averaging 0.4–0.5 seconds (6,400–8,000 samples), winstep=0.025 produced T_infer = 16–21 frames. Below approximately 40 frames, the CTC beam search produced an empty transcription — all blank labels, no output string. The command was silently dropped: no error, no log entry, no audio feedback to the operator. Overall WER was 34.8% in production versus 2.9% in the lab evaluation. Lab tests reused data_pipeline.py’s feature extraction code, so the train/test mismatch was not exposed. The discrepancy went undetected for 9 months. It was discovered only after a safety incident: an operator spoke “stop robot arm” during a rapid handover cycle. The command was 0.42 seconds — a short command, 17 frames at 40 fps, below CTC minimum. The command was dropped silently. The robot arm completed its movement cycle into an occupied zone. Two workers were injured. Post-incident regulatory investigation required a full audit of the voice control system. €380,000 total: €120,000 worker compensation, €180,000 production stoppage, €80,000 regulatory investigation and remediation.
# Southfield Python Speech Features Ltd. — python_speech_features 0.6 winstep fix
# python_speech_features 0.6; PyTorch 1.13; Python 3.10; NumPy 1.24
# 48 manufacturing commands; GRU(2-layer, hidden=256) + CTC decoder
# samplerate=16000; winlen=0.025 (400 samples); numcep=13; nfilt=26
#
# Problem: winstep=0.01 at training (100 fps) vs winstep=0.025 at inference (40 fps)
# T_train=148 vs T_infer=60 for same 1.5s utterance
# CTC decoder misalignment; short commands dropped silently
# Fix: winstep=0.01 at inference; save feature config in model checkpoint;
# assert config match at load time
import numpy as np
import torch
from python_speech_features import mfcc
# Feature extraction config — SINGLE SOURCE OF TRUTH
FEATURE_CONFIG = {
'samplerate': 16000,
'winlen': 0.025,
'winstep': 0.01, # 10ms frame shift = 100 fps — matches training
'numcep': 13,
'nfilt': 26,
'appendEnergy': True,
}
def extract_mfcc(signal: np.ndarray, config: dict) -> np.ndarray:
"""Extract MFCC features using config dict as single source of truth."""
feats = mfcc(
signal,
samplerate=config['samplerate'],
winlen=config['winlen'],
winstep=config['winstep'],
numcep=config['numcep'],
nfilt=config['nfilt'],
appendEnergy=config['appendEnergy'],
)
# T = floor((N - winlen_samples) / winstep_samples) + 1
# For N=24000 (1.5s at 16kHz), winstep=0.01: T=148; winstep=0.025: T=60
return feats
def save_model(model: torch.nn.Module, path: str, feature_config: dict) -> None:
"""Save model weights + feature config together."""
torch.save({
'model_state_dict': model.state_dict(),
'feature_config': feature_config,
}, path)
def load_model_with_config_check(model: torch.nn.Module, path: str,
inference_config: dict) -> None:
"""Load model and assert feature config matches saved config."""
checkpoint = torch.load(path, weights_only=False)
saved_config = checkpoint['feature_config']
if saved_config != inference_config:
raise ValueError(
f"Feature config mismatch — model was trained with {saved_config} "
f"but inference is using {inference_config}. "
f"WER will be severely degraded. Update inference config to match training."
)
model.load_state_dict(checkpoint['model_state_dict'])
# BUGGY inference: winstep=0.025 (copied from old notebook)
def extract_features_buggy(signal: np.ndarray) -> np.ndarray:
"""BUGGY: winstep=0.025 → 40 fps. Training used winstep=0.01 → 100 fps."""
return mfcc(signal, samplerate=16000, winlen=0.025, winstep=0.025, # BUG
numcep=13, nfilt=26, appendEnergy=True)
# For 1.5s utterance: T=60 (vs T_train=148) → CTC misalignment
# For 0.42s 'stop robot arm': T=17 → below CTC minimum → silent drop
# FIXED inference: winstep=0.01 from FEATURE_CONFIG
def extract_features_fixed(signal: np.ndarray) -> np.ndarray:
"""FIXED: winstep=0.01 matches training. Assert config at model load (see load_model_with_config_check)."""
return extract_mfcc(signal, FEATURE_CONFIG)
# For 1.5s utterance: T=148 (matches training) → CTC aligned
# For 0.42s 'stop robot arm': T=58 → above CTC minimum → command decoded correctly
def validate_feature_pipeline(signal_path: str, expected_config: dict) -> None:
"""Diagnostic: compare feature shapes from two code paths for the same audio."""
import soundfile as sf
signal, sr = sf.read(signal_path)
if sr != expected_config['samplerate']:
signal = signal # resample if needed
feats_expected = extract_mfcc(signal, expected_config)
T_expected = feats_expected.shape[0]
# Warn if another code path produces a different T
test_configs = [
{'winstep': 0.01, 'label': 'training default'},
{'winstep': 0.025, 'label': 'old notebook value (WRONG)'},
{'winstep': 0.0125, 'label': '80 fps variant'},
]
for t in test_configs:
cfg = {**expected_config, 'winstep': t['winstep']}
T = extract_mfcc(signal, cfg).shape[0]
status = 'OK' if T == T_expected else f'MISMATCH (T={T} vs expected T={T_expected})'
print(f" winstep={t['winstep']} ({t['label']}): T={T} → {status}")
Why train/inference feature extraction mismatches are invisible in unit tests and require config governance
The Southfield mismatch was invisible to every test in the CI pipeline because every test loaded audio and ran data_pipeline.py’s feature extraction — the same code used for training. The inference server’s feature extraction was never independently tested against the model checkpoint because there was no mechanism to detect that the two were different. The critical architectural mistake: treating feature extraction code as an implementation detail rather than part of the model’s specification. The fix requires two things: first, save the feature extraction configuration into every model checkpoint so it travels with the weights; second, assert that the inference configuration matches the saved configuration at every model load. If the configuration does not match, the system refuses to start rather than silently producing degraded output. This check runs in microseconds at startup and would have caught the Southfield mismatch immediately at first deployment, 9 months before the safety incident. For safety-critical command-and-control systems, an additional safeguard is required: a minimum-confidence gate on the CTC beam search output (reject the hypothesis if log-probability is below a threshold), plus a command-confirmation loop for irreversible actions (the system speaks the recognised command back to the operator and requires an explicit confirmation before executing). These two controls together would have prevented the safety incident even without fixing the winstep mismatch: the garbled “stop robot arm” would have either been rejected by the confidence gate or produced a confirmation request that the operator could not confirm.
Southfield Python Speech Features Ltd.’s retainer engagement was 2.0h: 1.0h triage (reproduce production WER on 50 test commands: 34.8%; extract features from same 5 audio files using both data_pipeline.py and inference_server.py; compare shapes: T=[148,131,162,88,174] vs T=[60,53,65,36,70]; grep mfcc( in codebase: two files, two winstep values; trace inference_server.py to origin notebook; confirm T mismatch is root cause by running inference with winstep=0.01: WER 2.9% restored; identify 12 short commands with T_infer<40 as source of silent drops); 0.25h root cause (confirm winstep=0.025 from old notebook; derive correct fix: winstep=0.01 at inference; plan config governance: save config in checkpoint, assert at load); 0.75h fix (update inference_server.py: set winstep=0.01; add FEATURE_CONFIG constant; add load_model_with_config_check(); add confidence gate: reject hypothesis if CTC log-probability < −3.0; add command confirmation TTS for conveyor and robot arm commands; re-run 48-command test suite: WER 2.9%; add validate_feature_pipeline() to deployment checklist; redeploy to factory floor; certify with safety engineer; 2.0h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- mir_eval developer on retainer — mir_eval 0.7; MedleyDB float voicing confidence passed as
ref_voicing; nonzero float truthy; 180,000 spurious voiced frames; Raw Pitch Accuracy 71%→89%; fix:ref_voicing=(conf ≥ 0.5); 2.5h - praat-parselmouth developer on retainer — parselmouth 0.4.3;
to_pitch(pitch_ceiling=600)marks soprano E5+ as unvoiced; 44% of frames NaN; vibrato extent 28 vs 61 cents; fix:pitch_ceiling=1500; 1.5h - dtaidistance developer on retainer — dtaidistance 2.3.11;
window=0.05float truncated to 0; Sakoe-Chiba band 0 → DTW = Euclidean; AFib clustering 61%; fix:window=int(0.05 × L)=15; 94%; 3.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 →