CoolFace
Modelpublic

Vansh180/deepfake-audio-wav2vec2

sourceHugging Facemitupdated 6mo agoView on Hugging Face
1likes2.9kdownloads
Model Card

๐Ÿงพ Model Card โ€” Deepfake-Audio-Wav2Vec2


๐Ÿง  Model Overview

Deepfake-Audio-Wav2Vec2 is a fine-tuned audio classification model trained to detect real vs spoofed (deepfake) speech audio.

The model is built on top of facebook/wav2vec2-base, a self-supervised speech representation model, and adapted for binary deepfake audio detection.

It learns subtle acoustic artifacts and synthetic speech patterns that differentiate genuine human recordings from AI-generated or manipulated audio samples.

This model is intended for:

  • โ€”Deepfake voice detection
  • โ€”Audio authenticity verification
  • โ€”Research in anti-spoofing systems
  • โ€”Security pipelines for voice-based applications

๐Ÿ—๏ธ Training Details

ParameterValue
Base Modelfacebook/wav2vec2-base
FrameworkHugging Face Transformers
Training HardwareGPU (CUDA)
Task TypeAudio Classification
Classesbonafide / spoof
Audio Sample Rate16 kHz
Input DurationFixed audio segments
OptimizationAdamW
Loss FunctionCross Entropy

๐ŸŽฏ Label Classes

  • โ€”๐ŸŸข Bonafide โ†’ Real / authentic speech
  • โ€”๐Ÿ”ด Spoof โ†’ Deepfake / synthetic audio

๐Ÿ“Š Evaluation Metrics

MetricScore
Accuracy92.8%
Precision89.7%
Recall88.0%
F1 Score88.4%

โœ… The model demonstrates strong detection performance across real and spoofed samples.


๐Ÿ“‚ Dataset Description

The model was trained on a balanced subset of the ASVspoof 2021 PA dataset for binary anti-spoofing classification.

The dataset includes:

  • โ€”Genuine speech recordings
  • โ€”Spoofed / manipulated audio samples
  • โ€”Replay and synthetic attack scenarios

Training was performed on balanced class samples to improve robustness across both labels.


๐Ÿ’ป Example Usage

python
import torch
import torchaudio
import numpy as np
from transformers import AutoFeatureExtractor, AutoModelForAudioClassification

model_id = "Vansh180/deepfake-audio-wav2vec2"

feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
model = AutoModelForAudioClassification.from_pretrained(model_id)

model.eval()

def predict_audio(audio_path):
    wav, sr = torchaudio.load(audio_path)

    if wav.shape[0] > 1:
        wav = wav.mean(dim=0, keepdim=True)

    inputs = feature_extractor(
        wav.squeeze().numpy(),
        sampling_rate=16000,
        return_tensors="pt"
    )

    with torch.no_grad():
        outputs = model(**inputs)
        probs = torch.softmax(outputs.logits, dim=1)

    prediction = torch.argmax(probs, dim=1).item()
    confidence = probs[0][prediction].item()

    return {
        "prediction": model.config.id2label[prediction],
        "confidence": confidence
    }

print(predict_audio("sample.wav"))