← writings

Voice Synthesis Detection Using Language Model-Based Speech Feature Extraction

This study began in 2023 and led to a paper in May 2024. As text-to-speech and voice-conversion systems improved, we wanted to look beyond local waveform and spectral cues for evidence of synthesis. We converted speech into discrete audio tokens and used a BERT model pretrained on text to extract features from their sequence.

The question was whether the codes produced by an audio codec retain temporal relationships that distinguish real speech from synthetic speech. We used Encodec as the tokenizer and BERT-Base as the sequence feature extractor.

Period2023 – 2024
TaskReal vs. synthetic speech detection
Core ideaEncodec + BERT

Looking for traces of synthesis in audio-token sequences

Many synthetic-speech detectors use features taken directly from the signal: spectra, phase, filter banks, or raw waveforms. Other approaches use pretrained speech models such as HuBERT. Both can work well, though their performance may depend on cues specific to a generator or recording condition.

We represented speech as a sequence of codebook indices. Encodec produced the codes during compression, and BERT modeled their context. Our hypothesis was that relationships between codes could expose longer patterns in synthetic speech that individual code values would miss.

The representation

Encodec maps speech to discrete codebook indices. BERT then reads those indices in sequence, allowing the detector to use relationships across time.

Using Encodec as an audio tokenizer for BERT

Encodec consists of an encoder, residual vector quantization (RVQ), and a decoder. The encoder maps the waveform to a continuous latent representation, which RVQ quantizes into integer indices from several codebooks. We passed these codes to BERT instead of decoding them back into speech.

Based on preliminary experiments, we used the output of the second quantization layer. The codes from each recording were arranged in a [2, 512] tensor: the first axis described the selected code configuration, and the second was the sequence length presented to BERT. These integer codes were converted to input embeddings for feature extraction.

BERT-Base had 12 Transformer encoder layers, a 768-dimensional hidden state, and 12 self-attention heads. It learned relationships between audio codes in temporal order, using the same context-modeling mechanism it applies to tokens in text.

Feature extractor passing Encodec encoder and RVQ outputs to BERT as discrete audio tokens
BERT processes the discrete codes produced by the Encodec encoder and RVQ. Figure 4 from the published paper.

Model configuration

  • Tokenizer — Encodec encoder + residual vector quantization.
  • Code selection — output of the second quantization layer.
  • Input shape — a `[2, 512]` discrete code sequence.
  • Context model — BERT-Base, 12 layers, 768 hidden dimensions, 12 heads.

Balancing ASVspoof 2019 and 2021 at 1:1

We evaluated on ASVspoof 2019 and ASVspoof 2021. Logical Access (LA) covers attacks based on text-to-speech and voice conversion; DeepFake (DF) focuses more directly on synthetic-speech detection. We used 2019 LA for the initial comparison and classifier selection, then tested on 2021 LA and DF under different attack conditions.

The original challenge data contained unequal numbers of bona fide and spoof samples, with one class roughly eight times larger than the other in some conditions. Overall accuracy can be misleading under this imbalance. We therefore constructed training, validation, and test splits with a 1:1 ratio of real to synthetic speech.

DatasetSplitBona fideSpoofTotal
2019 LATraining2,5802,5805,160
Validation2,5482,5485,096
Test7,3557,35514,710
2021 LATraining10,78410,78421,568
Validation2,7042,7045,408
Test3,3763,3766,752
2021 DFTraining11,82411,82423,648
Validation2,5482,5485,096
Test7,3557,35514,710

Why balance the splits?

Equal class counts make it easier to assess whether a detector separates both classes, rather than achieving high accuracy by favoring the more common one.

Testing the features with four classifiers

We wanted to assess the Encodec-BERT representation across different classifiers. We fed the same features to an FC-layer, a Transformer, ResNet-18, and ResNet2.

  • FC-layer tested whether a simple classifier could separate the two classes from the extracted features.
  • Transformer added a second stage of sequence modeling.
  • ResNet-18 learned patterns in the [512, 768] feature tensor through a residual network.
  • ResNet2 adjusted the input and output dimensions of ResNet-18's layers for the speech features.

In stage 1, we trained and evaluated all four on ASVspoof 2019 LA and compared them with ASSD, TSSDNet, and CCT. ASSD was a useful reference because it also combined an audio codec with a Transformer. In stage 2, we took the three stronger classifiers from 2019 LA—FC-layer, ResNet-18, and ResNet2—and evaluated them on 2021 LA and DF.

Four classifiers are compared on ASVspoof 2019 LA; three are then evaluated on ASVspoof 2021 LA and DF
The feature-extraction design stays the same while the classifiers and datasets change. Diagram redrawn from the paper's experimental procedure.
Pooled Encodec-BERT features passed to FC-layer, Transformer, ResNet-18, and ResNet2 classifiers
Four classifiers receive the same Encodec-BERT features. Figure 5 from the published paper.

Per-class accuracy and equal error rate

In the paper, Class 0 denotes real speech and Class 1 denotes synthetic speech. Per-class accuracy shows which class accounts for more errors. Balanced accuracy is the mean of the two class accuracies; overall accuracy is the fraction of all samples classified correctly.

EER is the error rate at the threshold where real speech is rejected as synthetic as often as synthetic speech is accepted as real. A lower EER indicates better separation between the classes.

Reading the results

  • Class 0 Accuracy — accuracy on real speech.
  • Class 1 Accuracy — accuracy on synthetic speech.
  • Balanced Accuracy — mean of the two class accuracies.
  • EER — the point where the two error rates are equal; lower is better.

An EER of 11.79% on 2021 DF

88.08%2019 LA accuracy
Encodec-BERT + ResNet2
15.98%2019 LA EER
Encodec-BERT + ResNet2
10.91%2021 LA EER
Encodec-BERT + FC-layer
11.79%2021 DF EER
Encodec-BERT + ResNet2

Stage 1: ASVspoof 2019 LA

ClassifierClass 0Class 1BalancedAccuracyEER
FC-layer80.84%99.08%89.96%87.88%17.09%
ResNet-1880.46%99.04%89.75%87.57%17.40%
ResNet281.27%98.69%89.98%88.08%15.98%
Transformer81.43%70.43%77.00%74.65%23.07%

ResNet2 gave the best results among these four configurations, with 88.08% accuracy and 15.98% EER. The FC-layer was close at 87.88% accuracy and 17.09% EER. Its performance suggested that the extracted features contained useful information even for a simple classifier.

The Transformer classifier reached only 70.43% accuracy on Class 1. Adding another sequence model after BERT did not improve detection in this setting.

Stage 2: ASVspoof 2021 LA and DF

DatasetClassifierBalanced AccuracyAccuracyEER
2019 LAResNet289.98%88.08%15.98%
2021 LAFC-layer89.42%88.67%10.91%
2021 DFResNet287.74%87.02%11.79%

The FC-layer performed best on 2021 LA: 84.52% Class 0 accuracy, 89.42% balanced accuracy, 88.67% overall accuracy, and 10.91% EER. On DF, ResNet2 performed best, with 91.28% Class 1 accuracy, 87.74% balanced accuracy, 87.02% overall accuracy, and 11.79% EER.

Per-class accuracy and EER for FC-layer, ResNet-18, and ResNet2 on ASVspoof 2021 LA
The FC-layer reached 88.67% accuracy and 10.91% EER on 2021 LA. Figure 6 from the published paper.
Per-class accuracy and EER for FC-layer, ResNet-18, and ResNet2 on ASVspoof 2021 DF
ResNet2 reached 87.02% accuracy and 11.79% EER on 2021 DF. Figure 7 from the published paper.

The 11.79% EER on DF was below the 15.64% reported for the compared systems using Mel-spectrogram, SincNet, or raw-audio features with CNN or ResNet classifiers. The Fbank-based reference model had an EER of 16.05%, and the CQT-based model had 18.30%. Encodec-BERT produced fewer errors under these comparison conditions.

Classifier choice still mattered

The FC-layer had the lowest EER on LA, while ResNet2 had the lowest on DF. Even with the same feature representation, the best classifier depended on the dataset and attack types.

Balanced counts did not eliminate differences between classes

Class 0 and Class 1 accuracy still differed after we balanced their counts at 1:1. The splits also differed in synthesis methods and attack difficulty. Classifiers that performed well on 2019 LA did not retain the same ranking on 2021 LA and DF.

These experiments tested the representation within the attack conditions covered by ASVspoof. They do not establish generalization to new text-to-speech or voice-conversion models, other codecs, compression and retransmission, or real telephone channels. Those conditions require separate evaluation.

What balancing does not fix

Equal sample counts reduce class imbalance, but do not remove differences in attack coverage. Performance on unseen generators and transmission channels remains an open question for this model.

What we learned from audio tokens

We used Encodec RVQ codes as BERT input tokens to extract features for synthetic-speech detection. After comparing four classifiers on 2019 LA, we evaluated the stronger three on 2021 LA and DF. The best DF result was 11.79% EER, compared with 15.64% for the reference systems discussed above.

The results support using a text-pretrained model to learn discriminative relationships in discrete audio sequences. They also show how much the final classifier and evaluation data affect the outcome. Testing on new generators and real transmission conditions remains necessary before drawing broader conclusions.

Paper

Publication · First author

Voice Synthesis Detection Using Language Model-Based Speech Feature Extraction

Seungmin Kim, Sohee Park, Daeseon Choi · Journal of the Korea Institute of Information Security & Cryptology 34(3), 439–449 · 2024