pub struct LocalVadDetector { /* private fields */ }Expand description
Local voice activity detector.
Provides voice activity detection using local processing without
external API calls. Uses the voice_activity_detector_silero_v5 crate for
speech detection and analysis.
Implementations§
Source§impl LocalVadDetector
impl LocalVadDetector
Sourcepub async fn detect_speech_from_data(
&self,
audio_data: ProcessedAudioData,
) -> Result<VadResult>
pub async fn detect_speech_from_data( &self, audio_data: ProcessedAudioData, ) -> Result<VadResult>
Sourcepub fn calculate_chunk_size(&self, sample_rate: u32) -> usize
pub fn calculate_chunk_size(&self, sample_rate: u32) -> usize
Dynamically calculates the optimal VAD chunk size for a given audio sample rate using the Silero VAD V5 model.
This function selects a chunk size (in samples) compatible with the Silero VAD V5 model’s strict requirements. For 8 kHz audio, only a 256-sample window is supported. For 16 kHz audio, only a 512-sample window is supported. For sample rates that are a multiple of 16 kHz (e.g., 32 kHz, 48 kHz), a 512-sample window is also used, as required by the model.
§Arguments
sample_rate: The audio sample rate in Hz (e.g., 8000, 16000)
§Returns
The chunk size in number of samples, as required by the Silero VAD V5 model.
§Model Reference
This logic follows the requirements of the Silero VAD V5 model.
§Panics
This function will panic if the sample rate is not supported by the model.
§Examples
use subx_cli::services::vad::LocalVadDetector;
let detector = LocalVadDetector::new(Default::default()).unwrap();
assert_eq!(detector.calculate_chunk_size(8000), 256);
assert_eq!(detector.calculate_chunk_size(16000), 512);Sourcepub fn audio_processor(&self) -> &VadAudioProcessor
pub fn audio_processor(&self) -> &VadAudioProcessor
Get the internal VadAudioProcessor instance (for advanced use, e.g. partial audio cropping)