pratikpawar0204
AI Voice Detection API - Competition Submission
dead0b1
import os
import librosa
import numpy as np
from dotenv import load_dotenv
# Load env vars
load_dotenv(os.path.join(os.path.dirname(__file__), '../../.env'))
# Language map for our supported languages
LANG_MAP = {
'en': 'English',
'ta': 'Tamil',
'hi': 'Hindi',
'ml': 'Malayalam',
'te': 'Telugu'
}
def identify_language(audio_path):
"""
Simple audio-based language detection using acoustic features.
Since SpeechBrain has compatibility issues, we use a heuristic approach
based on spectral characteristics typical of different language families.
This is a simplified fallback - for production, you'd want a proper
speech-to-text + language detection pipeline.
"""
try:
# Load audio
y, sr = librosa.load(audio_path, sr=16000)
# Extract basic features
mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
spectral_centroid = np.mean(librosa.feature.spectral_centroid(y=y, sr=sr))
spectral_bandwidth = np.mean(librosa.feature.spectral_bandwidth(y=y, sr=sr))
# Simple heuristic based on spectral characteristics
# Indian languages typically have different spectral patterns than English
# This is a placeholder - real detection would require ML model
# For now, return "auto-detected" with a note
# The actual language can be specified by the user in the API call
return "Auto (use language parameter for accuracy)"
except Exception as e:
print(f"LID Error: {e}")
return "Unknown"