Skip to main content

speech_prep/vad/
mod.rs

1//! Voice Activity Detection (VAD) with dual-metric analysis.
2//!
3//! This module provides real-time voice activity detection using a combination
4//! of energy and spectral flux metrics with adaptive baseline tracking.
5//!
6//! # Features
7//!
8//! - **Dual-metric analysis**: Energy + spectral flux for robust detection
9//! - **Adaptive thresholding**: Dynamic baseline tracking for varying noise
10//!   conditions
11//! - **Streaming support**: Maintains state across detect() calls for
12//!   continuous audio
13//! - **Configurable sensitivity**: Extensive tuning options via `VadConfig`
14//! - **Metrics instrumentation**: Performance and accuracy tracking via
15//!   `VadMetricsCollector`
16//!
17//! # Example
18//!
19//! ```rust,no_run
20//! use std::sync::Arc;
21//!
22//! use speech_prep::vad::{NoopVadMetricsCollector, VadConfig, VadDetector};
23//!
24//! let config = VadConfig::default();
25//! let metrics = Arc::new(NoopVadMetricsCollector);
26//! let detector = VadDetector::new(config, metrics)?;
27//!
28//! // Process audio samples
29//! let audio_samples: Vec<f32> = vec![0.0; 16000]; // 1 second at 16kHz
30//! let speech_segments = detector.detect(&audio_samples)?;
31//!
32//! for segment in speech_segments {
33//!     println!("Speech detected: {:?} to {:?}", segment.start_time, segment.end_time);
34//! }
35//! # Ok::<(), speech_prep::error::Error>(())
36//! ```
37
38pub mod config;
39pub mod detector;
40pub mod metrics;
41
42// Re-export main types for convenient access
43pub use config::VadConfig;
44pub use detector::{SpeechChunk, VadDetector};
45pub use metrics::{
46    AdaptiveThresholdSnapshot, NoopVadMetricsCollector, VadMetricsCollector, VadMetricsSnapshot,
47};