voice-detection-api / README.md
pratikpawar0204
Add HuggingFace Spaces deployment with combined FastAPI + Gradio app
2a31d3f
|
Raw
History Blame Contribute Delete
4.98 kB
---
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
```bash
pip install -r requirements.txt
```
### 2. Start the API Server
```bash
python src/api/main.py
```
The API will be available at `http://localhost:8000`
### 3. (Optional) Start Gradio UI
```bash
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
```json
{
"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
```json
{
"status": "success",
"language": "Tamil",
"classification": "AI_GENERATED",
"confidenceScore": 0.91,
"explanation": "Unnatural pitch consistency and robotic speech patterns detected"
}
```
### Error Response
```json
{
"status": "error",
"message": "Invalid API key or malformed request"
}
```
## πŸ” For Competition Endpoint Tester
### cURL Request Example
```bash
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)
```bash
# 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)
1. Push code to GitHub
2. Connect to [render.com](https://render.com)
3. Create Web Service β†’ Select repo
4. Build Command: `pip install -r requirements.txt`
5. 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.