Spaces:
Running
Running
metadata
title: AI Voice Detection API
emoji: π΅οΈ
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
π΅οΈ AI Voice Detection System
A production-ready API system to detect AI-generated voice samples vs Human speech, supporting Tamil, English, Hindi, Malayalam, and Telugu for the AI-Generated Voice Detection competition.
π― Project Overview
Objective: Build an API that accepts Base64-encoded MP3 audio and returns whether the voice is AI-generated or human, along with a confidence score and explanation.
Supported Languages (Fixed):
- Tamil
- English
- Hindi
- Malayalam
- Telugu
π Quick Start
1. Install Dependencies
pip install -r requirements.txt
2. Start the API Server
python src/api/main.py
The API will be available at http://localhost:8000
3. (Optional) Start Gradio UI
python src/gradio_app.py
Interactive UI at http://localhost:7861
π API Specification
Endpoint
POST /api/voice-detection
Headers
| Key | Value |
|---|---|
x-api-key |
Your API key |
Content-Type |
application/json |
Request Body
{
"language": "Tamil",
"audioFormat": "mp3",
"audioBase64": "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU2LjM2LjEwMAAAAAAA..."
}
Request Fields
| Field | Description |
|---|---|
language |
Exact name required: Tamil, English, Hindi, Malayalam, or Telugu |
audioFormat |
Always mp3 |
audioBase64 |
Base64-encoded MP3 audio |
Success Response
{
"status": "success",
"language": "Tamil",
"classification": "AI_GENERATED",
"confidenceScore": 0.91,
"explanation": "Unnatural pitch consistency and robotic speech patterns detected"
}
Error Response
{
"status": "error",
"message": "Invalid API key or malformed request"
}
π For Competition Endpoint Tester
cURL Request Example
curl -X POST https://your-domain.com/api/voice-detection \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"language": "Tamil",
"audioFormat": "mp3",
"audioBase64": "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU2LjM2LjEwMAAAAAAA..."
}'
π Deployment Options
Option 1: ngrok (Quick Testing)
# Install ngrok
pip install pyngrok
# In terminal 1: Start API
python src/api/main.py
# In terminal 2: Create tunnel
ngrok http 8000
Use the https://xxxx.ngrok.io URL for the endpoint tester.
Option 2: Render (Free Hosting)
- Push code to GitHub
- Connect to render.com
- Create Web Service β Select repo
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn src.api.main:app --host 0.0.0.0 --port $PORT
π Project Structure
why/
βββ data/
β βββ raw/
β β βββ human/ # Human voice samples
β β βββ ai/ # AI-generated samples
β βββ processed/ # Preprocessed audio
β βββ features/ # Extracted features
βββ models/ # Trained model files
β βββ dsp_model.pkl
β βββ dsp_cols.pkl
βββ src/
β βββ api/
β β βββ main.py # FastAPI application
β β βββ inference.py # Prediction pipeline
β β βββ schemas.py # Pydantic models
β β βββ lid.py # Language identification
β βββ features/
β β βββ extract_dsp.py # DSP feature extraction
β β βββ extract_embeddings.py
β βββ config.py # Configuration
β βββ download_human_data.py
β βββ generate_ai_data.py
β βββ preprocess.py
β βββ train.py
β βββ gradio_app.py # Gradio frontend
βββ .env # Environment variables
βββ requirements.txt # Dependencies
βββ EXPLANATION.md # Detailed system explanation
βββ README.md
π Model Performance
Overall Metrics
| Metric | Value |
|---|---|
| Test Accuracy | 95.7% |
| Model Type | Random Forest (Calibrated) |
| Features | 37 DSP features (MFCC, Spectral, Pitch) |
| Full API Latency | < 2 seconds |
βοΈ Configuration
Environment Variables (.env)
API_KEY=your_secure_api_key
HF_TOKEN=your_huggingface_token
β Competition Compliance
| Requirement | Implementation |
|---|---|
| Accepts Base64 MP3 input | β |
| Supports 5 languages | β Tamil, English, Hindi, Malayalam, Telugu |
| Returns AI_GENERATED or HUMAN | β |
| Returns confidenceScore (0-1) | β |
| Returns explanation | β |
| API Key authentication | β x-api-key header |
| No hardcoded responses | β Real ML model |
| No restricted external APIs | β Only local model |
π License
This project is for competition purposes.