Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ VoiceGuard

Real-Time AI Voice Deepfake Detection for Banking Call Centers

Python 3.11+ PyTorch 2.0+ FastAPI License: MIT

Detect synthetic voices in real-time β€” before fraud happens.


🎯 What is VoiceGuard?

VoiceGuard is a production-grade deepfake detection system that analyzes live call audio and identifies synthetic speech within the first 5–10 seconds of a call. It's designed to protect banking call centers from AI-powered voice cloning fraud.

The Problem

Modern generative AI can clone a person's voice from only a few seconds of audio. Fraudsters use this to bypass voice biometric authentication or impersonate customers during phone calls. Traditional defenses (phone number verification, caller ID) are easily spoofed.

The Solution

VoiceGuard provides audio-level deepfake detection using state-of-the-art pretrained anti-spoofing models:

  • AASIST β€” Audio Anti-Spoofing using Integrated Spectro-Temporal Graph Attention Networks (primary detector)
  • Wav2Vec2 β€” Fine-tuned deepfake audio classifier from HuggingFace (optional ensemble verifier)

πŸ—οΈ Architecture

Live Call Audio (SIP/RTP/WebSocket)
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Audio Stream Buffer (ring buffer, 5-10s)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Preprocessor                                    β”‚
β”‚  β”œβ”€ Resample to 16kHz                           β”‚
β”‚  β”œβ”€ Normalize [-1, 1]                           β”‚
β”‚  β”œβ”€ Voice Activity Detection                     β”‚
β”‚  └─ Spectral-gating noise reduction             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AASIST Model β”‚   β”‚ Wav2Vec2 Model   β”‚
β”‚ (85K params) β”‚   β”‚ (optional)       β”‚
β”‚ Primary      β”‚   β”‚ Ensemble         β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                    β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Ensemble Scorer                                 β”‚
β”‚  └─ Weighted average (0.7Γ—AASIST + 0.3Γ—W2V2)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Risk Classifier                                 β”‚
β”‚  β”œβ”€ score < 0.3  β†’ 🟒 LOW    β†’ ALLOW           β”‚
β”‚  β”œβ”€ 0.3 ≀ s < 0.7 β†’ 🟑 MEDIUM β†’ FLAG_FOR_REVIEWβ”‚
β”‚  └─ score β‰₯ 0.7  β†’ πŸ”΄ HIGH   β†’ BLOCK_AND_ALERT β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”
          β–Ό       β–Ό       β–Ό
       REST    WebSocket  Webhook
       API     Alert      Callback

πŸš€ Quick Start

1. Clone & Install

cd deepfake
pip install -r requirements.txt

2. Download Pretrained Weights

python scripts/download_weights.py

# Include Wav2Vec2 for ensemble mode:
python scripts/download_weights.py --include-wav2vec2

3. Start the Server

uvicorn api.app:app --host 0.0.0.0 --port 8000

4. Test with an Audio File

curl -X POST http://localhost:8000/api/v1/analyze \
  -F "file=@test_audio.wav" \
  -F "call_id=TEST-001"

5. View API Docs

Open http://localhost:8000/docs for interactive Swagger documentation.


🐳 Docker Deployment

# CPU mode
docker-compose up -d

# GPU mode (requires NVIDIA Container Toolkit)
docker-compose --profile gpu up -d

# Check health
curl http://localhost:8000/health

πŸ“‘ API Reference

REST Endpoints

Method Endpoint Description
GET / Service information
GET /health Health check
GET /health/ready Readiness probe (K8s)
GET /health/metrics Inference statistics
POST /api/v1/analyze Analyze uploaded audio file

WebSocket Streaming

Connect to ws://localhost:8000/api/v1/stream/{call_id} for real-time analysis.

Client β†’ Server:

{"type": "audio_chunk", "data": "<base64 PCM>", "seq": 1}
{"type": "end_stream"}

Server β†’ Client:

{"type": "buffer_status", "buffered_seconds": 3.2, "target_seconds": 6.0, "is_ready": false}
{"type": "analysis_result", "data": {"deepfake_score": 0.87, "risk_level": "HIGH", ...}}

Example Response

{
  "call_id": "CALL-2026-04-11-001",
  "deepfake_score": 0.87,
  "risk_level": "HIGH",
  "recommended_action": "BLOCK_AND_ALERT",
  "risk_description": "High probability of synthetic speech detected (score: 0.870)...",
  "confidence": 0.92,
  "inference_latency_ms": 34.5,
  "models_used": ["aasist"],
  "model_scores": {"aasist": 0.87},
  "spectral_analysis": {
    "spectral_centroid_hz": 1523.45,
    "pitch_mean_hz": 142.3,
    "pitch_stability": 0.0456,
    "harmonic_ratio": 2.34
  }
}

βš™οΈ Configuration

Configuration via environment variables or .env file:

cp .env.example .env
# Edit .env with your settings
Variable Default Description
MODEL_VARIANT aasist_l aasist (297K params) or aasist_l (85K params)
ENABLE_ENSEMBLE false Enable Wav2Vec2 ensemble
DEVICE auto auto, cuda, or cpu
BUFFER_DURATION_SEC 6.0 Audio buffer duration (seconds)
RISK_THRESHOLD_LOW 0.3 Below = LOW risk
RISK_THRESHOLD_HIGH 0.7 At/Above = HIGH risk
WEBHOOK_URL Fraud alert webhook URL
API_KEY API authentication key

πŸ“Š Performance

Latency benchmarks (P95):

Configuration GPU (V100) GPU (RTX 3060) CPU (i7-12700)
AASIST-L only ~25ms ~40ms ~160ms
AASIST full ~50ms ~80ms ~300ms
AASIST-L + preprocessing ~40ms ~60ms ~190ms
AASIST-L + Wav2Vec2 ensemble ~120ms ~180ms ~500ms+

Run your own benchmark:

python scripts/benchmark.py --model aasist_l --device auto --iterations 100

πŸ§ͺ Testing

# Unit tests
pytest tests/ -v

# Specific test module
pytest tests/test_audio_buffer.py -v
pytest tests/test_inference.py -v

πŸ“ Project Structure

deepfake/
β”œβ”€β”€ config/                     # Configuration
β”‚   β”œβ”€β”€ settings.py             # Pydantic settings
β”‚   β”œβ”€β”€ aasist.json             # AASIST model config
β”‚   └── aasist_l.json           # AASIST-L model config
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ aasist.py               # AASIST architecture
β”‚   └── weights/                # Pretrained weights (.pth)
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ audio_buffer.py         # Streaming audio buffer
β”‚   β”œβ”€β”€ preprocessor.py         # Audio preprocessing
β”‚   β”œβ”€β”€ feature_extractor.py    # Spectral diagnostics
β”‚   β”œβ”€β”€ inference_engine.py     # Model inference
β”‚   β”œβ”€β”€ ensemble.py             # Multi-model scoring
β”‚   └── risk_classifier.py      # Risk level classification
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ app.py                  # FastAPI application
β”‚   β”œβ”€β”€ schemas.py              # Pydantic models
β”‚   β”œβ”€β”€ middleware.py           # Auth & logging
β”‚   └── routes/
β”‚       β”œβ”€β”€ health.py           # Health endpoints
β”‚       β”œβ”€β”€ analyze.py          # File upload analysis
β”‚       └── stream.py           # WebSocket streaming
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ alert_service.py        # Fraud alert dispatch
β”‚   └── audit_logger.py         # Compliance logging
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ download_weights.py     # Download pretrained weights
β”‚   └── benchmark.py            # Latency benchmarking
β”œβ”€β”€ tests/                      # Unit & integration tests
β”œβ”€β”€ Dockerfile                  # Production container
β”œβ”€β”€ docker-compose.yml          # Orchestration
└── requirements.txt            # Dependencies

πŸ“„ Models & References

AASIST

Wav2Vec2 Deepfake Detector


πŸ“œ License

MIT License. See LICENSE for details.

AASIST model code is Β© 2021-present NAVER Corp., used under MIT license.

About

Audio deepfake detection in live audio streams with low-latency inference.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages