Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AI Voice Detector

A full-stack project for detecting whether an audio sample is likely generated by AI or captured from a real human voice. The solution combines a Hugging Face audio-classification model with preprocessing, real-time capture, API serving, and a browser-based demo interface.

This repository brings together multiple entry points:

  • backend API for audio upload and streaming analysis
  • desktop GUI for live monitoring
  • browser UI for testing the detection flow
  • model download and evaluation utilities
  • preprocessing and inference code for voice authenticity scoring

Project goal

The project is designed to classify audio clips as either:

  • AI voice / synthetic voice
  • Human voice / natural voice

The model is based on a Wav2Vec2 audio classifier fine-tuned for deepfake voice detection and is intended for research, experimentation, and demo use rather than as a production-grade security system.

High-level architecture

The repository is organized into a few complementary modules:

  • core/ — model loading and inference logic
  • detector/ — preprocessing and evaluation helpers
  • audio/ — live microphone capture utilities
  • backend/ — FastAPI API and audio-processing pipeline
  • frontend/ — React + Vite demo application
  • GUI/ — Tkinter desktop-based detection app
  • test_data/ — example audio folders used for testing

Folder structure

.
├── README.md
├── convert_to_onnx.py
├── download_model.py
├── test_model.py
├── Test_predict.py
├── backend/
│   ├── checking_audio_file.py
│   ├── converting_audio_file.py
│   └── server.py
├── core/
│   └── main.py
├── detector/
│   ├── detector.py
│   ├── onnx_model.py
│   ├── preprocessing.py
│   └── README.md
├── audio/
│   ├── README.md
│   ├── capture.py
│   └── captured_chunks/
├── frontend/
│   ├── README.md
│   ├── package.json
│   ├── package-lock.json
│   ├── index.html
│   ├── vite.config.js
│   └── src/
├── GUI/
│   └── app.py
├── test_data/
│   ├── ai/
│   └── human/
└── models/
    └── wav2vec2-deepfake-voice-detector/

Core workflow

  1. Audio is captured or uploaded as a waveform.
  2. The audio is resampled to 16 kHz and cleaned/preprocessed.
  3. The Wav2Vec2 model produces logits for AI vs human voice classes.
  4. The backend or app converts the result into a probability-based verdict.
  5. The frontend or GUI displays the outcome and optionally triggers alerts.

Model and detection logic

The project downloads the model from Hugging Face:

  • wav2vec2-deepfake-voice-detector
  • wav2vec2-large-xlsr-53

The core inference is implemented in core/main.py and uses a two-class classifier:

  • label 1 = AI voice
  • label 0 = human voice

The inference function returns (ai_probability, human_probability) based on softmaxed model outputs.

Key components

core/main.py

Responsible for loading the model with transformers and running prediction on input audio arrays. It ensures the model is loaded once and reused for subsequent inference calls.

detector/preprocessing.py

Handles the audio cleaning pipeline:

  • resampling to 16 kHz
  • background-noise reduction
  • silence trimming
  • amplitude normalization
  • conversion to float32 tensor-friendly format

backend/server.py

Provides a FastAPI backend with:

  • POST upload endpoint for audio file detection
  • WebSocket stream for real-time microphone or call monitoring
  • response payloads such as AI_Voice and Human_Voice

frontend/

A React app that simulates a call interface, supports file upload, and connects to the backend to analyze audio inputs.

GUI/app.py

A Tkinter app for desktop usage. It captures microphone input, evaluates chunks, and shows a status value while notifying the user when AI-like speech is detected.

audio/capture.py

Records incoming audio into fixed-duration chunks and saves each chunk as .wav. This is useful for capturing and validating detection behavior in controlled testing scenarios.

Setup and installation

Prerequisites

  • Python 3.9+
  • Node.js 18+ for the frontend
  • A working microphone or input device for live testing
  • A GPU is optional; CUDA is automatically used when available

Python dependencies

Install the main Python packages for the model pipeline, preprocessing, and API server:

pip install requirements.txt

Download the model

python download_model.py

This downloads the pretrained detection model into ./models/wav2vec2-deepfake-voice-detector.

Optional ONNX conversion

python convert_to_onnx.py

This exports the model to ONNX format for deployment or optimization workflows.

Running the project

1. Start the backend

cd backend
python server.py

The API listens on:

  • http://localhost:8000

Available detection route:

  • POST /detect-audio-file
  • WS /ws/detect-real-audio

2. Start the frontend UI

cd frontend
npm install
npm run dev

Then open the local Vite URL shown in the terminal.

3. Start the desktop GUI

python GUI/app.py

The GUI listens for audio input from a configured device and displays confidence values while running. It also raises desktop notifications when AI-like voice probability crosses a configured threshold.

4. Run evaluation on sample data

python test_model.py

This script loads the model and evaluates audio files found under the test dataset structure.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages