pysptk developer on retainer: mcep() alpha=0.41 is for 16 kHz — developer uses it on 8 kHz telephony audio — mel-warping mismatch — speaker verification EER 14.7% not 8.2% — 3 months — pysptk developer on monthly retainer
pysptk 0.1.21 • Python 3.10; pysptk.sptk.mcep(x, order=25, alpha=0.41); alpha=0.41 is recommended for 16 kHz audio; developer processes 8 kHz G.711 telephony audio; correct alpha for 8 kHz is 0.31; mel-filterbank bilinear-transform warping overweights sub-1.5 kHz band; F2 and F3 formant estimation error 15 – 22%; GMM-UBM speaker verification EER 14.7% (target 8.2%); 180,000 calls/month affected; fix: alpha=0.31 for 8 kHz • Eastfield Pysptk Ltd. (call centre fraud detection; £1.2M 3-yr contract; 3 months; 2.0h)
Eastfield Pysptk Ltd. built a speaker verification system for a UK telecoms operator under a £1.2M three-year contract. The system authenticated callers by comparing the mel-cepstral coefficients of their current call against an enrolled voiceprint, using a GMM-UBM (Gaussian Mixture Model - Universal Background Model) framework. Audio source: G.711 μ-law telephone recordings decoded to 8 kHz 16-bit PCM. The mel-cepstrum feature extraction pipeline: apply a 20ms Hamming window to each speech frame; call pysptk.sptk.mcep(frame_windowed, order=25, alpha=0.41, etype=1); stack 25 mel-cepstral coefficients per frame; apply cepstral mean and variance normalisation (CMVN) over the session; compute delta and delta-delta features; pass 75-dimensional feature vectors to the GMM scorer. The developer took the alpha=0.41 value directly from the pysptk README code example. The documentation example demonstrated 16 kHz audio; the actual telephony audio was 8 kHz. The EER on the development test set was 14.7% (false acceptance rate ≈ 7.4% at the equal-error operating point). The target SLA required EER ≤ 10% and a production target of 8.2%. Over three months, the team tried increasing the UBM Gaussian count from 128 to 512 (EER improved from 14.7% to 13.9%), increasing the cepstral order from 25 to 36 (EER rose to 15.1%), using order=12 (EER 15.8%), applying feature warping normalisation (EER 14.1%), and experimenting with vocal tract length normalisation (VTLN) with warp factors 0.85 – 1.15. No combination reached the 10% SLA threshold.
The mechanism: pysptk.sptk.mcep()’s alpha parameter controls the mel-filter warping coefficient in the SPTK bilinear transform. The bilinear transform maps each digital frequency ω (0 to π radians/sample) to a warped frequency via a first-order all-pass filter with coefficient α. At α=0, the transform is the identity (no warping). As α increases toward 1, the warped frequency axis increasingly stretches the low-frequency region and compresses the high-frequency region, approximating the mel scale. The recommended α values are calibrated so that the warped frequency axis best approximates the mel scale over the signal’s usable frequency band: 8 kHz audio (Nyquist = 4 kHz) requires α=0.31 to distribute cepstral resolution evenly across the mel-scale frequency range 0 – 4 kHz; 16 kHz audio (Nyquist = 8 kHz) requires α=0.41 for the wider 0 – 8 kHz band. Using α=0.41 on 8 kHz audio causes the bilinear transform to apply warping designed for the 0 – 8 kHz band to the 0 – 4 kHz band. The warping allocates approximately 60% of the cepstral resolution to frequencies below 1.5 kHz (which carries glottal source characteristics, common across speakers) and only 40% to the 1.5 – 4.0 kHz range (which carries the second and third formants, F2 and F3, that most distinguish individual speakers). With α=0.31, the warping correctly places approximately 50% of the resolution below 1.5 kHz and 50% in the 1.5 – 4.0 kHz band. The GMM-UBM trained on over-warped features built speaker models that over-indexed on low-frequency energy and under-captured the inter-speaker formant differences in the mid-frequency range. The log-likelihood ratio distributions for genuine and impostor trials overlapped by 14.7% EER rather than the expected 8.2%. No exception was raised; mcep() accepted alpha=0.41 silently for 8 kHz input.
# Eastfield Pysptk Ltd. — pysptk 0.1.21 alpha fix
# pysptk 0.1.21; Python 3.10; NumPy 1.24
# 8kHz G.711 telephony audio; GMM-UBM speaker verification
# £1.2M 3-year contract; call centre fraud detection
#
# Problem: alpha=0.41 is for 16kHz audio; correct alpha for 8kHz is 0.31
# mel-warping overweights sub-1.5kHz band on 8kHz audio
# F2/F3 formant region (1.5–4kHz) underrepresented in cepstrum
# GMM-UBM cannot separate speakers; EER 14.7% (target 8.2%)
# Fix: alpha=0.31 for 8kHz; EER 8.4% after UBM rebuild
import numpy as np
import pysptk
# Recommended mcep() alpha values by sample rate (from SPTK documentation)
MCEP_ALPHA = {
8000: 0.31, # telephony G.711, G.729
10000: 0.35,
11025: 0.37,
16000: 0.41, # wideband, AMR-WB, Whisper
22050: 0.45,
24000: 0.44,
32000: 0.50,
44100: 0.58, # CD audio
48000: 0.59, # broadcast
}
def extract_mel_cepstrum_buggy(frame: np.ndarray, order: int = 25) -> np.ndarray:
"""BUGGY: alpha=0.41 hardcoded regardless of sample rate."""
# Apply Hamming window (pysptk does NOT window internally)
windowed = frame * np.hamming(len(frame))
# BUG: alpha=0.41 is for 16kHz audio
# On 8kHz audio: mel-warping designed for 0–8kHz applied to 0–4kHz
# Overweights sub-1.5kHz (speaker-common features)
# Underweights 1.5–4kHz (F2/F3 formants: speaker-discriminative)
return pysptk.sptk.mcep(windowed, order=order, alpha=0.41, etype=1) # WRONG
def extract_mel_cepstrum(frame: np.ndarray, sample_rate: int,
order: int = 25) -> np.ndarray:
"""FIXED: use correct alpha for the actual sample rate."""
if sample_rate not in MCEP_ALPHA:
raise ValueError(
f"No recommended mcep alpha for sample_rate={sample_rate}Hz. "
f"Known rates: {sorted(MCEP_ALPHA.keys())}. "
f"Use the nearest value or consult the SPTK documentation."
)
alpha = MCEP_ALPHA[sample_rate]
# pysptk.sptk.mcep() does NOT apply windowing internally.
# Always window the frame with Hamming (or Blackman for TTS) BEFORE calling mcep().
windowed = frame * np.hamming(len(frame))
return pysptk.sptk.mcep(
windowed,
order=order,
alpha=alpha, # 8kHz → 0.31; 16kHz → 0.41
maxiter=50,
threshold=1e-4,
etype=1, # input is log spectrum (etype=0 for amplitude, etype=1 for log)
eps=1e-6,
min_det=1e-6,
itype=0 # itype=0: windowed time-domain input
)
def extract_features_session(audio_pcm: np.ndarray, sample_rate: int,
frame_len_ms: float = 20.0,
frame_shift_ms: float = 10.0,
order: int = 25) -> np.ndarray:
"""
Extract mel-cepstral features for a full call session.
Returns CMVN-normalised features, shape (n_frames, order+1).
"""
frame_len = int(sample_rate * frame_len_ms / 1000.0)
frame_shift = int(sample_rate * frame_shift_ms / 1000.0)
frames = []
for start in range(0, len(audio_pcm) - frame_len, frame_shift):
frame = audio_pcm[start:start + frame_len].astype(np.float64)
# Skip near-silent frames (voice activity detection gate)
frame_energy = 10.0 * np.log10(np.mean(frame ** 2) + 1e-10)
if frame_energy < -40.0: # dB threshold
continue
mcc = extract_mel_cepstrum(frame, sample_rate, order=order)
frames.append(mcc)
if not frames:
raise ValueError(f"No voiced frames found in audio segment (length={len(audio_pcm)} samples).")
features = np.array(frames) # (n_frames, order+1)
# Cepstral mean and variance normalisation (CMVN) over session
mean = features.mean(axis=0, keepdims=True)
std = features.std(axis=0, keepdims=True) + 1e-10
return (features - mean) / std
def validate_eer_threshold(eer: float, sample_rate: int,
eer_threshold: float = 0.12) -> None:
"""
Assert that the speaker verification EER meets the minimum threshold.
EER ≥ 0.12 on telephony almost always indicates wrong alpha or missing CMVN.
"""
alpha = MCEP_ALPHA.get(sample_rate, 'unknown')
if eer >= eer_threshold:
raise ValueError(
f"Speaker verification EER {eer:.1%} exceeds threshold {eer_threshold:.0%} "
f"for sample_rate={sample_rate}Hz (mcep alpha={alpha}). "
f"Most likely causes: "
f"(1) Wrong alpha — check MCEP_ALPHA table: {sample_rate}Hz → {alpha}; "
f"(2) Missing CMVN — apply session-level cepstral mean and variance normalisation; "
f"(3) Insufficient UBM Gaussian count — telephony needs ≥256; "
f"(4) Audio not decoded to base sample rate — G.711 must be decoded to 8kHz PCM."
)
print(f"EER validation PASSED: {eer:.1%} < {eer_threshold:.0%} at {sample_rate}Hz (alpha={alpha}).")
Why the wrong alpha produces a valid output with degraded speaker discrimination and why EER improvement plateaus regardless of model complexity
The mel-warping mismatch is a systematic bias, not a random error. Every mel-cepstral coefficient extracted from every 8 kHz frame with alpha=0.41 has the same directional error: too much energy captured from below 1.5 kHz, too little from 1.5 – 4.0 kHz. The features are internally consistent — every frame is biased in the same way — so CMVN normalisation cannot correct it (CMVN removes per-channel mean and scales by standard deviation, which removes zero-mean Gaussian bias but not a directional frequency-domain bias). Increasing the GMM Gaussian count from 128 to 512 helps marginally (EER 14.7% – 13.9%) because more Gaussians can model the low-frequency space more precisely, but the missing high-frequency speaker information cannot be recovered from features that never captured it. The developers’ intuition that “more model capacity will close the gap” was correct in principle but could not overcome a 30-percentile relative EER gap caused by systematically wrong features. The EER eventually plateaued at ≈13.5% with any model configuration, because the information needed to distinguish speakers in the 1.5 – 4.0 kHz band was not present in the feature vectors at all. The diagnostic: compare the mel-cepstral coefficient distribution (histograms of c[2] – c[8]) between known-different speakers using α=0.41 vs α=0.31. With the correct alpha, the inter-speaker KL divergence for c[2] – c[5] (encoding F2/F3 formant region) is approximately 0.42; with the wrong alpha, it falls to 0.19 — a 55% reduction in discriminative power for the most speaker-identifying cepstral coefficients. This distributional comparison can be done in under 10 minutes on a 50-call development set and definitively identifies the alpha mismatch before a 3-month tuning effort.
Eastfield Pysptk Ltd.’s retainer engagement was 2.0h: 0.3h triage (request mcep() call site; alpha=0.41 on 8 kHz audio identified immediately; audio confirmed as 8 kHz G.711 decode; correct alpha for 8 kHz is 0.31); 0.3h root cause (compute bilinear transform frequency mapping for α=0.41 and α=0.31 at Nyquist=4 kHz; confirm: α=0.41 warps the 0 – 4 kHz band as though it were 0 – 8 kHz; mel-cepstrum c[4] captures ~1.2 kHz with α=0.41 but ~2.1 kHz with α=0.31 — shifted by nearly one octave; KL divergence check on 50-call dev set confirms 55% reduction in F2/F3 discriminative power with wrong alpha); 0.5h fix (change alpha=0.41 to alpha=0.31; rebuild UBM with correct features on 2,000-call training set — 18 minutes; test on 400-trial dev set: EER 8.6%; add MCEP_ALPHA lookup with assertion; add EER gate: assert EER < 12%); 0.9h validation (full 1,000-trial test set: EER 8.4%; confirm improvement across five speaker cohort demographics; deploy to production pipeline; monitor live call stream for 48h: EER 8.5% ± 0.3% stable; 2.0h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- crepe developer on retainer — crepe 0.0.13; Python 3.9;
crepe.predict(audio, sr)returnsfrequencyin Hz; developer interprets as MIDI note number; melody contour shifted by 69 notes (12× octave); TTS prosody wrong; fix:librosa.hz_to_midi(frequency); 1.5h - parselmouth developer on retainer — parselmouth 0.4.3; Python 3.10;
snd.to_pitch()returns pitch in Hz; developer computes delta pitch as Hz difference; semitone difference requires log-ratio; prosody transfer 3× too sensitive at high pitch; fix:12 * np.log2(f1 / f2); 2.0h - pyworld developer on retainer — pyworld 0.3.4; Python 3.10;
pyworld.harvest(x, fs)returnsf0with 0.0 for unvoiced; developer computes log pitch on all frames;np.log(0.0)→-inf; NaN propagates through mel-cepstrum delta; voice conversion breaks for all unvoiced consonants; fix: unvoiced mask before log; 2.0h
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 →