YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Voice Anti-Spoofing System ποΈ
This repository contains a complete deep learning project for detecting AI-generated (spoofed) voices. The system is built on a robust workflow that includes data preprocessing, comparative model training, advanced fine-tuning, and deployment into interactive full-stack web applications.
The core of the project is a comparative study between multiple deep learning architectures to determine the most effective approach for audio anti-spoofing.
Features
- Comparative Model Analysis: Systematically trains and evaluates three distinct deep learning architectures:
- Baseline CNN: A simple convolutional neural network to establish a performance baseline.
- Deeper CNN: An enhanced CNN with more layers and batch normalization for improved stability.
- Vision Transformer (ViT): A state-of-the-art, pre-trained model fine-tuned for spectrogram analysis.
- Efficient Two-Stage Training: Implements a robust workflow to first train models from scratch on a large dataset and then fine-tune them with data augmentation to combat overfitting and improve generalization.
- Interactive Web Applications: Deploys the trained models using two separate full-stack applications, allowing users to upload audio files and receive real-time predictions.
- High-Performance Backend: Built with FastAPI for an asynchronous, fast, and reliable API.
- Modern Frontend: A responsive and user-friendly interface built with React.js.
Project Workflow & Notebooks
The project's development is documented across four Jupyter notebooks, each serving a specific purpose in the workflow.
FakeVsReal_1.ipynb: The initial exploratory notebook. This was used for early-stage development, prototyping the basic data loading pipeline, and training a simple CNN on a smaller subset of the data (for-rerecdataset) to ensure the core concepts were viable.SamplingDataset.ipynb: A utility notebook created to solve a practical problem. Its purpose is to create a smaller, representative subset of the massivefor-originaldataset. This allows for rapid prototyping and debugging of models without waiting hours for training on the full dataset.FakeVsReal_2.ipynb: The main initial training script. This notebook scales up the process by training all three models (Baseline CNN, Deeper CNN, ViT) from scratch on the full, largefor-originaldataset. The trained models from this stage are saved (..._model.pth) for the next step.FakeVsReal_2_FineTunning.ipynb: The final and most important stage. This notebook loads the initially trained models and fine-tunes them for a few more epochs using advanced techniques like data augmentation and a lower learning rate. This step is crucial for combating overfitting and significantly improving the models' final performance. The final, production-ready models (..._finetuned.pth) are saved from this notebook.
Model Performance
The final test accuracies for the fine-tuned models on the unseen test set are as follows:
| Model | Test Accuracy |
|---|---|
| Fine-Tuned Baseline CNN | 99.51% |
| Fine-Tuned Deeper CNN | 99.63% |
| Fine-Tuned ViT | 99.75% |
π Web Application
To make the trained AI model accessible to everyone, a full-stack web application was developed and deployed.
π Live Web App
https://voiceantispoofing.netlify.app/
π» Web App GitHub Repository
https://github.com/Laabh-Gupta/Voice-Anti-Spoofing-Web-App
βοΈ Web App Features
- Upload audio directly from the browser
- Real-time prediction: REAL vs FAKE voice
- FastAPI backend deployed on Railway
- React frontend deployed on Netlify
- Clean UI & responsive design for users
- Uses the final fine-tuned AI model for inference
Setup and Installation
Follow these steps to set up the project and run the applications locally.
1. Clone the Repository
git clone [https://github.com/Laabh-Gupta/Fake_Vs_Real_Voice_Detection.git](https://github.com/Laabh-Gupta/Fake_Vs_Real_Voice_Detection.git)
cd Fake_Vs_Real_Voice_Detection
2. Download the Dataset
This project uses "The Fake or Real Dataset" from Kaggle.
- Download Link: https://www.kaggle.com/datasets/mohammedabdeldayem/the-fake-or-real-dataset
- Download the
for-original.zipfile. - Unzip it and place the resulting
FakeVsRealDataset(for-original)folder inside the root of your cloned project directory.
3. Set Up the Python Backend Environment
This project uses Conda to manage backend dependencies.
A. Create the Conda Environment:
This command creates a new environment named fastapi_env with all the necessary libraries.
conda create -n fastapi_env python=3.10
conda activate fastapi_env
B. Install Dependencies: Install all required Python packages into your new environment.
pip install "fastapi[all]" uvicorn torch torchaudio torchvision python-multipart SoundFile
Note: If you have a CUDA-enabled GPU, you may want to install a specific PyTorch version that supports it. Visit the PyTorch website for the correct command.
4. Set Up the React Frontend Environment
The frontend requires Node.js and npm.
A. Navigate to a Frontend Directory: Choose one of the frontend applications to set up first.
# Example for the Baseline CNN frontend
cd "Baseline Web App/audio_classifier_app_baseline"
B. Install Dependencies: This command installs all the necessary React packages.
npm install
Repeat this step for the "ViT Web App/audio-classifier-frontend" directory as well.
Running the Web Applications
To run an application, you must start both its backend and frontend servers simultaneously in two separate terminals.
Example: Running the Baseline CNN Application
Terminal 1: Start the Backend Server
- Activate the Conda environment:
conda activate fastapi_env - Navigate to the backend directory:
cd "Baseline Web App/audio_app_baseline" - Start the Uvicorn server:
Your AI backend is now running atuvicorn main:app --reloadhttp://127.0.0.1:8000.
Terminal 2: Start the Frontend Server
- Navigate to the frontend directory:
cd "Baseline Web App/audio_classifier_app_baseline" - Start the React development server:
Your browser will automatically open tonpm starthttp://localhost:3000, where you can use the application.
Note on Model Choice: While both applications are fully functional, the Baseline Model Application is recommended as it is the most accurate model practically.
License
This project is licensed under the MIT License. See the LICENCE file for details.
