speechbrain developer on retainer: ECAPA-TDNN verify_batch() cosine similarity threshold set to 0.5 — EER threshold is 0.25 — FRR 68.1% not 2.1% — 68% of voice enrollments rejected on login — $280,000 — 8 months — speechbrain developer on monthly retainer

speechbrain 0.5.16 • torch 2.0.1 • Python 3.10; SpeakerRecognition.verify_batch() returns cosine similarity ∈ (−1, 1); genuine-pair cosine mean 0.42 ± 0.18 (VoxCeleb1-H hard); EER at threshold ≈ 0.25; threshold set to 0.5; FRR 68.1%, FAR 1.8%; voice-authenticated document signing rejects 68% of legitimate logins; fix: threshold=0.25 from ROC analysis on enrollment-verification pairs • Southfield SpeechBrain Auth Ltd. (6-person voice auth startup; 8 months; 2.0h)

Southfield SpeechBrain Auth Ltd. is a 6-person startup building a voice-authenticated document signing platform. Clients enroll their voice by recording a passphrase once at account setup; at signing time they speak the passphrase again and the system verifies their identity before countersigning the document. The developer used SpeechBrain’s pre-trained ECAPA-TDNN speaker recognition model from HuggingFace (speechbrain/spkrec-ecapa-voxceleb). The verify_batch() API returns a cosine similarity score and a boolean prediction; the threshold that determines “same speaker” vs “different speaker” defaults to 0.25 in some SpeechBrain versions but was overridden in the deployment code:

# verify.py — voice authentication at document signing (speechbrain 0.5.16)
import torch
import torchaudio
from speechbrain.inference.speaker import SpeakerRecognition

classifier = SpeakerRecognition.from_hparams(
    source="speechbrain/spkrec-ecapa-voxceleb",
    savedir="pretrained_models/spkrec-ecapa-voxceleb"
)

def verify_speaker(enrollment_path: str, verification_path: str) -> bool:
    wav_enroll, sr_e = torchaudio.load(enrollment_path)   # 16000 Hz mono
    wav_verify, sr_v = torchaudio.load(verification_path)  # 16000 Hz mono

    score, prediction = classifier.verify_batch(
        wav_enroll, wav_verify,
        wav_lens1=torch.tensor([1.0]),
        wav_lens2=torch.tensor([1.0]),
        threshold=0.5    # ← bug: naive "above 50% similar = same speaker"
    )
    return bool(prediction)

# Results after 6 weeks of production:
# Support ticket #001: "My voice login doesn't work — tried 8 times"
# Support ticket #002: "Authentication always fails. I'm speaking clearly."
# Support ticket #003: "Enrolled on Monday. Can't sign anything on Tuesday."
# Total support tickets (6 weeks): 847
# Average score for genuine pairs in production: 0.39 (threshold 0.5 → rejected)
# Average score for impostor pairs in production: 0.09 (threshold 0.5 → rejected — good)
# FRR at threshold 0.5: 68.1%  (68 out of 100 legitimate users rejected every attempt)

SpeechBrain’s ECAPA-TDNN produces L2-normalized speaker embeddings; verify_batch() computes the cosine similarity between two embeddings using torch.nn.functional.cosine_similarity(e1, e2). Cosine similarity measures the angle between two embedding vectors — 1.0 means identical direction, 0.0 means orthogonal, −1.0 means opposite. For the same speaker recorded in strictly identical conditions, cosine similarities approach 0.9–0.98. For the same speaker across enrollment (account setup) and verification (months later, different device, real-world noise), the cosine similarity distribution is centered much lower.

The genuine-pair cosine distribution vs. the 0.5 threshold

# ECAPA-TDNN (spkrec-ecapa-voxceleb) score distributions
# Source: VoxCeleb1-H hard evaluation set (online-hard mining, cross-session)
#         Reflects real-world deployment: different recording sessions,
#         different environments, spontaneous speech (not read passphrase)
#
# Genuine pairs (same speaker, different utterances/sessions):
#   Mean cosine similarity: 0.42
#   Std deviation:          0.18
#   10th percentile:        0.21
#   25th percentile:        0.30
#   50th percentile (median): 0.43
#   75th percentile:        0.55
#   90th percentile:        0.63
#
# Impostor pairs (different speakers):
#   Mean cosine similarity: 0.07
#   Std deviation:          0.14
#   90th percentile:        0.26
#   95th percentile:        0.32
#
# EER: threshold where FRR = FAR ≈ 0.25 → EER ≈ 0.8%
#
# Threshold analysis:
#   threshold=0.25:  FRR=2.1%,  FAR=2.3%  ← near EER, balanced
#   threshold=0.35:  FRR=9.4%,  FAR=0.8%  ← stricter, some inconvenience
#   threshold=0.50:  FRR=68.1%, FAR=1.8%  ← rejects most genuine users ✗
#   threshold=0.70:  FRR=94.3%, FAR=0.1%  ← nearly everyone rejected ✗
#
# Why 0.42 mean is below the intuitive 0.5 "similarity" threshold:
#   The genuine-pair distribution reflects cross-session variation:
#   - Enrollment: quiet room, desktop microphone, careful speech
#   - Verification (months later): iPhone earpiece, street noise, faster speech
#   - Different room acoustics → different reverb on formants
#   - Emotional state: signing a tense legal document vs. calm enrollment
#   ECAPA-TDNN embeddings are stable within sessions but have
#   genuine cross-session spread of ±0.18 std, centering below 0.5

Why eight months of model improvements could not lower the FRR

The team correctly identified that users were being rejected and attributed the problem to model quality. If the model produced higher cosine scores for genuine pairs, they reasoned, the threshold of 0.5 would be achievable. Over eight months they ran:

# Month 1: Switch from ECAPA-TDNN to x-vector model (spkrec-xvect-voxceleb)
#   FRR at threshold 0.5: 70.2%  (worse — x-vector is an older architecture)
#
# Month 2: Require 5 enrollment utterances; compute mean embedding as voiceprint
#   FRR at threshold 0.5: 64.3%  (improvement, but still 2 in 3 users rejected)
#   Genuine-pair mean cosine: 0.42 → 0.47 (5-utterance average helps slightly)
#
# Month 3: Mandate high-quality enrollment microphone (USB condenser)
#   FRR at threshold 0.5: 61.7%  (enrollment quality up; verification still mobile)
#
# Month 4: Voice conversion data augmentation during fine-tuning
#   Fine-tune ECAPA-TDNN on augmented corpus to increase cross-condition robustness
#   FRR at threshold 0.5: 60.1%  (small gain from augmentation)
#
# Month 5: Automatic silence trimming before computing embeddings
#   FRR at threshold 0.5: 59.8%  (essentially no change — silence was not the issue)
#
# Month 6: Implement ZT-norm score normalization
#   ZT-norm shifts and scales cosine scores by cohort statistics
#   FRR at threshold 0.5: 48.3%  (meaningful improvement — scores shifted up)
#   But still: nearly half of genuine users rejected
#
# Month 7: Fine-tune on 500 hours of mobile-to-desktop cross-condition pairs
#   FRR at threshold 0.5: 44.1%
#
# Month 8: Request retainer engagement — still FRR > 40% with threshold 0.5
#
# Retainer triage (2.0h):
#   Step 1: Plot score histogram for 500 genuine and 2000 impostor pairs
#          Genuine: mean 0.43, std 0.17 (improved from baseline 0.42 via months of tuning)
#          Impostor: mean 0.09, std 0.13
#          Observation: at threshold 0.5, the boundary cuts through the PEAK of genuine dist
#   Step 2: Compute ROC curve → EER threshold = 0.26, EER = 1.1%
#   Step 3: At threshold 0.26: FRR = 2.1%, FAR = 2.3%  ← acceptable for document signing
#   Step 4: Root cause: threshold 0.5 was set by assumption, not by measurement
#          The model is performing well (EER 1.1%) — the threshold is wrong
#   Fix: threshold = 0.25 (or use ROC-derived threshold from development set)

The retainer consultant identified the threshold calibration error in 2.0 hours: 0.75h to audit the threshold value against the ECAPA-TDNN cosine similarity distribution for genuine pairs, plot the score histogram, confirm that threshold 0.5 bisects the genuine-pair distribution (most genuine pairs score 0.3–0.55, with the threshold rejecting the lower 68%); 0.75h to collect 500 genuine and 2000 impostor pairs from production enrollment logs, compute the full ROC curve, identify the EER threshold at 0.25–0.26 (EER 1.1%), and measure FRR and FAR at multiple candidate thresholds; 0.5h to update the threshold, run a retrospective on the 847 support tickets (all were genuine-pair rejections, not impostors), and add a threshold validation check. Hours logged to HourTab with per-session breakdown.

# Fixed verify.py — threshold derived from ROC analysis

import torch, numpy as np
import torchaudio
from speechbrain.inference.speaker import SpeakerRecognition

classifier = SpeakerRecognition.from_hparams(
    source="speechbrain/spkrec-ecapa-voxceleb",
    savedir="pretrained_models/spkrec-ecapa-voxceleb"
)

# Threshold derived from ROC analysis on 500 genuine + 2000 impostor production pairs
# EER threshold = 0.26 (EER = 1.1%)
# At threshold 0.25: FRR = 2.1%, FAR = 2.3%  ← deployed threshold
VERIFICATION_THRESHOLD = 0.25

assert 0.1 <= VERIFICATION_THRESHOLD <= 0.6, (
    "ECAPA-TDNN cosine threshold must be calibrated via ROC analysis on "
    "enrollment-verification pairs from your deployment environment. "
    "NEVER use 0.5 as a default — genuine-pair cosine mean is ~0.42, not 0.75+"
)

def verify_speaker(enrollment_path: str, verification_path: str) -> tuple:
    wav_enroll, _ = torchaudio.load(enrollment_path)
    wav_verify, _ = torchaudio.load(verification_path)

    score, prediction = classifier.verify_batch(
        wav_enroll, wav_verify,
        wav_lens1=torch.tensor([1.0]),
        wav_lens2=torch.tensor([1.0]),
        threshold=VERIFICATION_THRESHOLD    # ← 0.25, not 0.5
    )
    return float(score), bool(prediction)

# After fix (production, 4-week post-deployment measurement):
# FRR at threshold 0.25: 2.1%   (was 44.1% with months of model tuning at 0.5)
# FAR at threshold 0.25: 2.3%   (acceptable for document signing use case)
# Support tickets: 847 → 12 per 6 weeks  (genuine-pair rejections resolved)
#
# Key lesson: the ECAPA-TDNN model was performing at EER 1.1% the entire time.
# 8 months of model improvements reduced EER from 0.8% → 1.1% (threshold confusion
# from 0.5 overcame the model quality improvement in the wrong direction).
# The business value was always locked behind a one-line threshold change.

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 →