An intelligent REST API that detects whether a voice sample is AI-generated or spoken by a real human. Supports 5 languages: Tamil, English, Hindi, Malayalam, and Telugu.The system accepts audio input and return a structred JSON response.
- ✅ Multi-language Support: Tamil, English, Hindi, Malayalam, Telugu
- ✅ High Accuracy: Advanced audio feature analysis
- ✅ Secure API: API key authentication
- ✅ RESTful Design: Standard JSON request/response
- ✅ Docker Ready: Easy deployment with containerization
- ✅ Real-time Processing: Fast voice classification
- ✅ Confidence Scoring: Returns 0.0-1.0 confidence scores
- ✅ Detailed Explanations: Provides reasoning for classification
- Python 3.11 or higher
- Docker (optional, but recommended)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/voice-detection-api.git
cd voice-detection-api
# Build and run with Docker Compose
docker-compose up --build
# API will be available at http://localhost:8000# Clone the repository
git clone https://github.com/YOUR_USERNAME/voice-detection-api.git
cd voice-detection-api
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On Mac/Linux:
source venv/bin/activate
# Install dependencies
pip install -r req.txt
# Run the API
python main.py
# API will be available at http://localhost:8000http://localhost:8000 (for local development)
https://your-deployment-url.com (for production)
GET /healthResponse:
{
"status": "healthy"
}GET /Response:
{
"service": "AI Voice Detection API",
"status": "running",
"version": "1.0.0",
"supported_languages": ["Tamil", "English", "Hindi", "Malayalam", "Telugu"]
}POST /api/voice-detectionHeaders:
Content-Type: application/json
x-api-key: sk_test_123456789
Request Body:
{
"language": "English",
"audioFormat": "mp3",
"audioBase64": "BASE64_ENCODED_AUDIO_DATA"
}Success Response (200 OK):
{
"status": "success",
"language": "English",
"classification": "AI_GENERATED",
"confidenceScore": 0.85,
"explanation": "Detected highly consistent pitch, uniform spectral characteristics suggesting synthetic generation"
}Error Response (401 Unauthorized):
{
"status": "error",
"message": "Invalid API key"
}Error Response (400 Bad Request):
{
"status": "error",
"message": "Invalid base64 encoding"
}All requests to /api/voice-detection must include an API key in the header:
x-api-key: sk_test_123456789
To change the API key, edit the main.py file:
VALID_API_KEY = "your_new_api_key_here"Or set it as an environment variable:
export API_KEY="your_new_api_key_here"# Test with an audio file
python test_api.py sample.mp3 English
# This will:
# 1. Encode your audio to base64
# 2. Send it to the API
# 3. Display the results# First, encode your audio file
python encode_audio.py sample.mp3 English
# This generates test_payload.json
# Then use curl:
curl -X POST http://localhost:8000/api/voice-detection \
-H "Content-Type: application/json" \
-H "x-api-key: sk_test_123456789" \
-d @test_payload.json# Test health endpoint
curl http://localhost:8000/health
# Test with invalid API key (should return 401)
curl -X POST http://localhost:8000/api/voice-detection \
-H "Content-Type: application/json" \
-H "x-api-key: wrong_key" \
-d '{"language":"English","audioFormat":"mp3","audioBase64":"test"}'The API uses advanced audio signal processing to detect AI-generated voices by analyzing:
- AI voices often have unnaturally consistent pitch
- Measures pitch variability and range
- Low variability indicates synthetic generation
- Analyzes frequency distribution
- AI voices show more uniform spectral characteristics
- Checks spectral centroid, rolloff, and bandwidth
- Captures vocal tract characteristics
- AI voices have distinct MFCC patterns
- Analyzes 20 MFCC coefficients and their variations
- Measures audio energy consistency
- AI voices maintain very consistent energy levels
- Human voices have natural energy fluctuations
- Analyzes harmonic vs. percussive components
- AI voices have artificial harmonic ratios
- Detects synthetic audio generation patterns
- Signal distribution analysis (skewness, kurtosis)
- Zero-crossing rate patterns
- Temporal consistency metrics
if confidence_score >= 0.50:
classification = "AI_GENERATED"
else:
classification = "HUMAN"- 🇮🇳 Tamil (தமிழ்)
- 🇬🇧 English
- 🇮🇳 Hindi (हिन्दी)
- 🇮🇳 Malayalam (മലയാളം)
- 🇮🇳 Telugu (తెలుగు)
voice-detection-api/
│
├── main.py # Main FastAPI application
├── req.txt # Python dependencies
├── Dockerfile # Docker container configuration
├── docker-compose.yml # Docker Compose setup
├── render.yaml # Render.com deployment config
├── railway.json # Railway.app deployment config
│
├── test_api.py # API testing script
├── encode_audio.py # Audio encoding utility
├── monitor_api.py # API monitoring tool
│
└── README.md # This file
-
Push to GitHub:
git init git add . git commit -m "Initial commit" git remote add origin https://github.com/YOUR_USERNAME/voice-detection-api.git git push -u origin main
-
Go to Render.com
-
Click "New +" → "Web Service"
-
Connect your GitHub repository
-
Configure:
- Environment: Docker
- Plan: Free
-
Click "Create Web Service"
-
Wait 5-10 minutes for deployment
-
Your API URL:
https://your-app.onrender.com
- Push code to GitHub (see above)
- Go to Railway.app
- New Project → Deploy from GitHub
- Select your repository
- Railway auto-detects Docker
- Generate Domain in Settings
- Done!
# Install flyctl
curl -L https://fly.io/install.sh | sh
# Login
fly auth login
# Deploy
fly launch
fly deploygcloud run deploy voice-detection-api \
--source . \
--platform managed \
--region us-central1 \
--allow-unauthenticatedimport requests
import base64
# Read audio file
with open("sample.mp3", "rb") as f:
audio_bytes = f.read()
audio_base64 = base64.b64encode(audio_bytes).decode('utf-8')
# Prepare request
url = "https://your-api-url.com/api/voice-detection"
headers = {
"Content-Type": "application/json",
"x-api-key": "sk_test_123456789"
}
payload = {
"language": "English",
"audioFormat": "mp3",
"audioBase64": audio_base64
}
# Send request
response = requests.post(url, headers=headers, json=payload)
result = response.json()
print(f"Classification: {result['classification']}")
print(f"Confidence: {result['confidenceScore']}")
print(f"Explanation: {result['explanation']}")const fs = require('fs');
const axios = require('axios');
// Read and encode audio
const audioBuffer = fs.readFileSync('sample.mp3');
const audioBase64 = audioBuffer.toString('base64');
// Send request
const response = await axios.post(
'https://your-api-url.com/api/voice-detection',
{
language: 'English',
audioFormat: 'mp3',
audioBase64: audioBase64
},
{
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_test_123456789'
}
}
);
console.log(response.data);# Encode audio
BASE64_AUDIO=$(base64 -w 0 sample.mp3)
# Send request
curl -X POST https://your-api-url.com/api/voice-detection \
-H "Content-Type: application/json" \
-H "x-api-key: sk_test_123456789" \
-d "{
\"language\": \"English\",
\"audioFormat\": \"mp3\",
\"audioBase64\": \"$BASE64_AUDIO\"
}"# API Key (optional - defaults to sk_test_123456789)
export API_KEY="your_custom_api_key"
# Port (optional - defaults to 8000)
export PORT=8000In docker-compose.yml:
services:
api:
environment:
- API_KEY=your_custom_api_key
- PORT=8000Solution:
pip install -r req.txtSolution:
- Check that
x-api-keyheader is set correctly - Verify the API key matches the one in
main.py
Solution:
- Ensure audio is properly base64 encoded
- Use
encode_audio.pyto encode your audio files - Check that the entire base64 string is included
Solution:
- Audio processing is CPU-intensive
- Consider upgrading server resources
- Reduce audio file size/quality if possible
Solution:
# Rebuild without cache
docker-compose build --no-cache
docker-compose up- Average Response Time: 2-5 seconds per request
- Supported Audio Length: Up to 60 seconds recommended
- Max File Size: 5MB (base64 encoded)
- Concurrent Requests: Depends on deployment resources
- ✅ API key authentication required
- ✅ No data persistence (audio is not stored)
- ✅ Input validation on all requests
- ✅ Rate limiting recommended for production
- ✅ HTTPS enforced on deployment platforms
| Code | Meaning |
|---|---|
| 200 | Success - Voice analyzed successfully |
| 400 | Bad Request - Invalid input format |
| 401 | Unauthorized - Invalid/missing API key |
| 500 | Internal Server Error - Processing error |
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Created for India AI Impact Buildathon { Problem Statement 1:- AI-Generated Voice Detection (Mutli-Langauge)}
- FastAPI framework for the API structure
- Librosa library for audio processing
- scikit-learn for feature analysis
- Docker for containerization
For issues and questions:
- Open an issue on GitHub
- Check the troubleshooting section above
- Review the API documentation
API Endpoint: https://voice-detection-production.up.railway.app/api/voice-detection
API Key: sk_test_123456789
# Health check
curl https://your-deployment-url.com/health
# Voice detection test
curl -X POST https://your-deployment-url.com/api/voice-detection \
-H "Content-Type: application/json" \
-H "x-api-key: sk_test_123456789" \
-d @test_payload.json- Framework: FastAPI 0.115.0
- Python Version: 3.11+
- Audio Processing: Librosa 0.10.2
- Containerization: Docker
- Deployment: Render.com / Railway.app / Fly.io / Google Cloud Run
- Machine learning model integration
- Support for more audio formats (WAV, FLAC)
- Batch processing support
- WebSocket for real-time streaming
- Database integration for analytics
- Admin dashboard
- Rate limiting
- Caching layer
- Multi-region deployment
Made with ❤️ for the India AI Impact Buildathon
⭐ Star this repository if you find it useful!