fix(audio): address CoreML VAD review feedback
This commit is contained in:
@@ -94,6 +94,7 @@ pub struct AppleCoreMlVad {
|
||||
handle: *mut c_void,
|
||||
symbols: AppleSileroSymbols,
|
||||
accum: Vec<f32>,
|
||||
frame_scratch: Box<[f32; SILERO_COREML_FRAME_16K]>,
|
||||
last_probability: f32,
|
||||
}
|
||||
|
||||
@@ -130,6 +131,7 @@ impl AppleCoreMlVad {
|
||||
handle,
|
||||
symbols,
|
||||
accum: Vec::with_capacity(SILERO_COREML_FRAME_16K),
|
||||
frame_scratch: Box::new([0.0; SILERO_COREML_FRAME_16K]),
|
||||
last_probability: 0.0,
|
||||
})
|
||||
}
|
||||
@@ -148,14 +150,13 @@ impl AppleCoreMlVad {
|
||||
}
|
||||
}
|
||||
|
||||
fn calc_level(&mut self, audio_frame: &[f32]) -> f32 {
|
||||
debug_assert_eq!(audio_frame.len(), SILERO_COREML_FRAME_16K);
|
||||
fn calc_level(&mut self) -> f32 {
|
||||
let mut probability = self.last_probability;
|
||||
let rc = unsafe {
|
||||
(self.symbols.process)(
|
||||
self.handle,
|
||||
audio_frame.as_ptr(),
|
||||
audio_frame.len(),
|
||||
self.frame_scratch.as_ptr(),
|
||||
self.frame_scratch.len(),
|
||||
&mut probability,
|
||||
)
|
||||
};
|
||||
@@ -183,11 +184,10 @@ impl VoiceActivityDetector for AppleCoreMlVad {
|
||||
|
||||
self.accum.extend_from_slice(samples);
|
||||
if self.accum.len() >= SILERO_COREML_FRAME_16K {
|
||||
let audio_frame: Vec<f32> = self.accum[..SILERO_COREML_FRAME_16K].to_vec();
|
||||
self.calc_level(&audio_frame);
|
||||
let overflow: Vec<f32> = self.accum.drain(SILERO_COREML_FRAME_16K..).collect();
|
||||
self.accum.clear();
|
||||
self.accum.extend_from_slice(&overflow);
|
||||
self.frame_scratch
|
||||
.copy_from_slice(&self.accum[..SILERO_COREML_FRAME_16K]);
|
||||
self.calc_level();
|
||||
drop(self.accum.drain(..SILERO_COREML_FRAME_16K));
|
||||
}
|
||||
|
||||
VadOutput {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Voice activity detection backends and helpers.
|
||||
//!
|
||||
//! iOS capture feeds VoiceProcessingIO-processed microphone frames into
|
||||
//! this module and uses the realtime-safe WebRTC fallback. Other
|
||||
//! platforms may use a model-backed detector when available so
|
||||
//! VoiceActivity mode never collapses back to Continuous transmit.
|
||||
//! Apple capture feeds VoiceProcessingIO/CoreAudio-processed microphone
|
||||
//! frames into this module and prefers Apple CoreML Silero VAD when the
|
||||
//! Swift bridge is linked. WebRTC VAD remains the realtime-safe fallback;
|
||||
//! non-Apple platforms may use ONNX-backed Silero when available.
|
||||
|
||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
||||
pub mod apple_coreml;
|
||||
|
||||
Reference in New Issue
Block a user