How an AI Voice Detector Works: Features, Classifiers and a Toy Python Example Tania Alwan published an explainer on how AI voice detectors, known in research as spoofing countermeasures, work: they frame the task as binary classification scored by equal error rate (EER) and the tandem detection cost function (t-DCF), evaluated mainly on ASVspoof challenge data. The piece covers hand-crafted spectral features, the two main detector families, and the limits of commercial accuracy claims, then walks through a toy Python detector that extracts eight features from a short-time Fourier transform and trains a logistic regression on self-generated harmonic-tone clips. Alwan is explicit that the toy detects only the artifacts she planted and says nothing about real cloned voices. By Tania Alwan Cloned and synthetic voices are now easy to make, so "is this voice real?" has become a practical question for podcasters, journalists, call centres and musicians. An AI voice detector tries to answer it automatically. This post explains how these detectors work under the hood, what the research community uses to test them, where they fail, and then builds a deliberately tiny detector in Python so you can see the moving parts. Spoiler: the toy works on toy data. Real detection is much harder, and I will be explicit about why. In research, this problem is usually called spoofing detection or anti-spoofing , and the detector is a countermeasure CM . The task is binary classification: The detector outputs a score, and a threshold turns the score into a decision. Because false alarms and misses both matter, the field reports the equal error rate EER : the operating point where the false-acceptance rate equals the false-rejection rate. Lower is better. Most published AI voice detector work is evaluated on data from the ASVspoof challenge series https://www.asvspoof.org/ , which started in 2015 and was built to protect automatic speaker verification ASV systems. Alongside EER, ASVspoof also uses the tandem detection cost function t-DCF , which measures how a countermeasure affects a speaker verification system it protects. Synthetic speech can sound convincing to people while still leaving statistical traces in the signal. Classic pipelines start with hand-crafted spectral features: Why high frequencies? Many speech generation pipelines work at limited sample rates or use vocoders whose artefacts show up in particular bands. But this is a property of specific systems, not a law of nature, and it changes with every new generator. Detectors broadly fall into two families: Commercial "AI voice detector" products generally do not publish their architectures or training data, so treat their accuracy claims with care unless they come with an independent evaluation. This is the most important section. Because detection after the fact is fragile, researchers also work on watermarking synthetic audio at generation time, for example AudioSeal San Roman et al. https://arxiv.org/abs/2401.17264 . That only helps when the generator cooperates, so the two approaches complement each other. The script below generates its own fake "voices" harmonic tones plus breath-like noise so it runs without downloading any dataset. "Synthetic" clips get a steadier pitch and a band-limited noise floor, a crude stand-in for vocoder artefacts. It extracts eight summary features mean and standard deviation of four descriptors from a short-time Fourier transform and trains a logistic regression. This is a toy. It detects the artefacts I planted. It says nothing about real cloned voices. pip install numpy scikit-learn python import numpy as np from sklearn.linear model import LogisticRegression from sklearn.model selection import train test split from sklearn.metrics import roc curve SR = 16000 rng = np.random.default rng 0 def fake voice synthetic, dur=1.0, cutoff=4000 : """Toy 'voice': a harmonic tone plus breath noise. 'Bona fide' clips get pitch jitter and full-band noise; 'synthetic' clips get a steadier pitch and a band-limited noise floor a crude stand-in for vocoder artefacts . Not real speech """ t = np.arange int SR dur / SR f0 = rng.uniform 100, 220 jitter = 0.002 if synthetic else 0.02 f0 track = f0 1 + jitter np.cumsum rng.standard normal t.size / np.sqrt t.size phase = 2 np.pi np.cumsum f0 track / SR y = sum np.sin k phase / k for k in range 1, 30 noise = rng.standard normal t.size 0.05 if synthetic: remove most energy above cutoff Hz from the noise floor spec = np.fft.rfft noise spec int cutoff t.size / SR : = 0.1 noise = np.fft.irfft spec, n=t.size return y + noise / np.max np.abs y + noise def features y, n fft=512, hop=256 : frames = np.lib.stride tricks.sliding window view y, n fft ::hop mag = np.abs np.fft.rfft frames np.hanning n fft , axis=1 + 1e-10 freqs = np.fft.rfftfreq n fft, 1 / SR log spec = np.log mag centroid = mag freqs .sum 1 / mag.sum 1 flatness = np.exp log spec.mean 1 / mag.mean 1 hf ratio = mag :, freqs 4000 .sum 1 / mag.sum 1 flux = np.r 0, np.sqrt np.diff log spec, axis=0 2 .mean 1 feats = centroid / 1000, flatness, hf ratio, flux return np.array f x for x in feats for f in np.mean, np.std labels = np.array 0 200 + 1 200 0 = bona fide, 1 = synthetic X = np.array features fake voice bool l for l in labels X tr, X te, y tr, y te = train test split X, labels, test size=0.3, random state=0, stratify=labels clf = LogisticRegression max iter=1000 .fit X tr, y tr scores = clf.predict proba X te :, 1 fpr, tpr, = roc curve y te, scores i = np.nanargmin np.abs fpr - 1 - tpr print f"accuracy: {clf.score X te, y te :.2f}" print f"EER: { fpr i + 1 - tpr i / 2:.3f}" A "new generator": same idea, different artefact cutoff at 7 kHz X new = np.array features fake voice bool l , cutoff=7000 for l in labels print f"accuracy on unseen 'generator': {clf.score X new, labels :.2f}" With these seeds, my run printed: accuracy: 0.95 EER: 0.083 accuracy on unseen 'generator': 0.72 Your numbers may differ slightly with other library versions. The last line is the interesting one: the same classifier, tested on "synthetic" clips whose artefact sits at 7 kHz instead of 4 kHz, drops sharply. That is the generalisation problem from the research above, in miniature. Things worth trying: clf.coef to see which cues the model leans on. If you build or use voice-cloning tools, detection is only half the story. Consent matters too: platforms such as Voicestars https://www.voicestars.co/create-ai-voice let people create AI versions of their own voice, and clear consent rules are part of making synthetic voices trustworthy. Disclosure: this article was written in partnership with Voicestars.