pub struct VadStateMachine { /* private fields */ }Expand description
The QUIET→STARTING→SPEAKING→STOPPING hysteresis shared by every VAD impl.
A faithful port of pipecat VADAnalyzer._run_analyzer: the analyzer supplies
the raw per-window voice confidence and a smoothed volume; this machine
gates speaking = confidence >= threshold && volume >= min_volume and applies
the debounce: STARTING must persist start_frames windows to become SPEAKING,
STOPPING must persist stop_frames windows to become QUIET. start_frames/
stop_frames are derived from start_secs/stop_secs and the window duration
(window_samples / sample_rate), exactly as pipecat rounds them.
Implementations§
Source§impl VadStateMachine
impl VadStateMachine
Sourcepub fn new(sample_rate: u32, window_samples: usize, params: VadParams) -> Self
pub fn new(sample_rate: u32, window_samples: usize, params: VadParams) -> Self
Build a state machine for an analyzer producing window_samples-sample
windows at sample_rate, with the given debounce/threshold params.
Sourcepub fn set_params(&mut self, params: VadParams)
pub fn set_params(&mut self, params: VadParams)
Replace the params and recompute debounce, resetting the running state to
QUIET (mirrors pipecat set_params).
Sourcepub fn advance(&mut self, confidence: f32, volume: f32) -> VadState
pub fn advance(&mut self, confidence: f32, volume: f32) -> VadState
Advance one analysis window. confidence is the model’s voice probability
for the window; volume is the window’s normalized loudness in [0, 1]
already computed/smoothed by the analyzer (pipecat does the exponential
smoothing in the base analyzer before this gate). Returns the new state.