Spaces:
Sleeping
Sleeping
File size: 1,207 Bytes
b3f89f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class RuleBasedDetector:
def __init__(self, config: dict):
self.config = config
def predict(self, features: dict) -> tuple[str, float, str]:
"""
Apply heuristic rules to features.
Returns (label, confidence, explanation).
"""
score = 0
reasons = []
# Rules ported from AI-Generated-Voice-Detection
pitch_std_thresh = self.config.get("pitch_std_threshold", 50.0)
spec_cent_thresh = self.config.get("spectral_centroid_threshold", 3000.0)
rms_std_thresh = self.config.get("rms_std_threshold", 0.01)
if features["pitch_std"] < pitch_std_thresh:
score += 1
reasons.append("Unnaturally stable pitch detected")
if features["spectral_centroid_mean"] > spec_cent_thresh:
score += 1
reasons.append("Overly smooth spectral characteristics")
if features["rms_std"] < rms_std_thresh:
score += 1
reasons.append("Low energy variation typical of synthetic speech")
if score >= 2:
return "AI_GENERATED", 0.65, "; ".join(reasons)
return "HUMAN", 0.55, "Natural human-like speech dynamics observed"
|