"""Conservative speech detection for the opt-in staging candidate. No absolute loudness cutoff: normalize a detection-only copy so quiet speech is assessed by its shape. Decode the original waveform, not boosted noise. """ import numpy as np def speech_regions(audio, sr=16000): if sr != 16000: raise ValueError('Speech gate requires 16 kHz audio') audio = np.asarray(audio, dtype=np.float32) if audio.ndim != 1 or not np.isfinite(audio).all(): raise ValueError('Speech gate requires finite mono audio') if not audio.size or not np.any(audio): return [] from faster_whisper.vad import get_speech_timestamps, VadOptions peak = float(np.max(np.abs(audio))) detection_audio = audio * (0.5 / peak) if peak < 0.5 else audio return get_speech_timestamps(detection_audio, VadOptions( threshold=0.35, min_speech_duration_ms=100, min_silence_duration_ms=500, speech_pad_ms=250, max_speech_duration_s=28, ), sampling_rate=sr)