pub struct FrameAdapter { /* private fields */ }Expand description
Adapts audio frames to match a VAD backend’s requirements.
Buffers incoming samples and produces frames of the exact size required by the wrapped detector. Also handles sample rate validation.
Implementations§
Source§impl FrameAdapter
impl FrameAdapter
Sourcepub fn new(inner: Box<dyn VoiceActivityDetector>) -> Self
pub fn new(inner: Box<dyn VoiceActivityDetector>) -> Self
Create a new frame adapter wrapping a VAD detector.
Sourcepub fn capabilities(&self) -> &VadCapabilities
pub fn capabilities(&self) -> &VadCapabilities
Returns the capabilities of the wrapped detector.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Returns the required sample rate.
Sourcepub fn frame_size(&self) -> usize
pub fn frame_size(&self) -> usize
Returns the required frame size in samples.
Sourcepub fn process(
&mut self,
samples: &[i16],
sample_rate: u32,
) -> Result<Option<f32>, VadError>
pub fn process( &mut self, samples: &[i16], sample_rate: u32, ) -> Result<Option<f32>, VadError>
Process audio samples, buffering until a complete frame is available.
Returns Some(probability) when a complete frame was processed,
or None if more samples are needed.
§Arguments
samples- Audio samples (any length)sample_rate- Sample rate of the input audio
§Errors
Returns an error if the sample rate doesn’t match the detector’s requirements.
Sourcepub fn process_all(
&mut self,
samples: &[i16],
sample_rate: u32,
) -> Result<Vec<f32>, VadError>
pub fn process_all( &mut self, samples: &[i16], sample_rate: u32, ) -> Result<Vec<f32>, VadError>
Process all complete frames in the buffer.
Returns a vector of probabilities, one for each complete frame processed. Useful when you want to process multiple frames at once.
Sourcepub fn process_latest(
&mut self,
samples: &[i16],
sample_rate: u32,
) -> Result<f32, VadError>
pub fn process_latest( &mut self, samples: &[i16], sample_rate: u32, ) -> Result<f32, VadError>
Returns the last probability from processing, or 0.0 if no frame was complete.
This is a convenience method for real-time processing where you only care about the most recent result.
Sourcepub fn buffered_samples(&self) -> usize
pub fn buffered_samples(&self) -> usize
Returns the number of samples currently buffered.
Sourcepub fn timings(&self) -> ProcessTimings
pub fn timings(&self) -> ProcessTimings
Returns accumulated processing timings from the inner detector.