Speaker Verification Implementation Speaker Verification answers the question "is this voice the voice of a specific person?" — a binary problem with a confidence threshold. It is used for biometric authentication, voice bot fraud protection, and two-factor voice authentication. ### Verification types: Text-Dependent — the phrase is fixed ("my passphrase"). EER 0.5–1.5%, but vulnerable to replay attacks. Text-Independent — any phrase. EER 1–3%, more practical. Anti-Spoofing — additional protection against synthesized/recorded voices. ### Implementation on ECAPA-TDNN
from speechbrain.pretrained import SpeakerRecognition
import torchaudio
verifier = SpeakerRecognition.from_hparams(
source="speechbrain/spkrec-ecapa-voxceleb",
savedir="tmp_verification"
)
def verify_speaker(
enrollment_audio: str,
test_audio: str,
threshold: float = 0.25
) -> tuple[bool, float]:
"""
enrollment_audio: эталонная запись зарегистрированного пользователя
threshold: порог для Accept/Reject (подбирается под нужный FAR/FRR)
"""
score, prediction = verifier.verify_files(enrollment_audio, test_audio)
is_same = float(score) >= threshold
return is_same, float(score)
```### Configuring the threshold for security requirements | Threshold | FAR | FRR | Application | |-------|-----|-----------| | 0.1 | 5% | 1% | Low risk | | 0.25 | 1% | 5% | Balanced | | 0.4 | 0.1% | 15% | High security | FAR = False Accept Rate, FRR = False Reject Rate. ### Anti-Spoofing```python
# Проверка на синтетический голос
from speechbrain.pretrained import EncoderClassifier
antispoofing = EncoderClassifier.from_hparams(
source="speechbrain/asvspoof-cqcc-lcnn",
savedir="tmp_antispoofing"
)
def is_genuine(audio_path: str) -> bool:
signal, _ = torchaudio.load(audio_path)
prediction = antispoofing.classify_batch(signal)
return prediction[3][0] == "genuine"
```### Best Practices: - Collect 3-5 reference phrases upon registration (averaging improves EER by 30%) - Update the reference phrase every 3-6 months (voice changes) - Add a timestamp and nonce to protect against replay attacks Timeframe: Basic system - 1 week. With anti-spoofing and profile management - 2-3 weeks.







