VAD fixes + some calibrations
This commit is contained in:
parent
82eddf5d4c
commit
64eb1093d5
8 changed files with 593 additions and 157 deletions
41
crates/jarvis-core/src/audio_buffer.rs
Normal file
41
crates/jarvis-core/src/audio_buffer.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
pub struct AudioRingBuffer {
|
||||
buffer: VecDeque<Vec<i16>>,
|
||||
max_frames: usize,
|
||||
}
|
||||
|
||||
impl AudioRingBuffer {
|
||||
// Create buffer that holds `seconds` worth of audio at given frame_size and sample_rate
|
||||
pub fn new(seconds: f32, frame_size: usize, sample_rate: usize) -> Self {
|
||||
let frames_per_second = sample_rate / frame_size;
|
||||
let max_frames = (frames_per_second as f32 * seconds) as usize;
|
||||
|
||||
Self {
|
||||
buffer: VecDeque::with_capacity(max_frames),
|
||||
max_frames,
|
||||
}
|
||||
}
|
||||
|
||||
// Push a frame, dropping oldest if full
|
||||
pub fn push(&mut self, frame: &[i16]) {
|
||||
if self.buffer.len() >= self.max_frames {
|
||||
self.buffer.pop_front();
|
||||
}
|
||||
self.buffer.push_back(frame.to_vec());
|
||||
}
|
||||
|
||||
// Drain all buffered frames into a single vec
|
||||
pub fn drain_all(&mut self) -> Vec<Vec<i16>> {
|
||||
self.buffer.drain(..).collect()
|
||||
}
|
||||
|
||||
// Get frame count
|
||||
pub fn len(&self) -> usize {
|
||||
self.buffer.len()
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.buffer.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -163,8 +163,8 @@ pub const DEFAULT_VAD: VadBackend = VadBackend::Energy;
|
|||
pub const DEFAULT_GAIN_NORMALIZER: bool = false;
|
||||
|
||||
// VAD settings
|
||||
pub const VAD_ENERGY_THRESHOLD: f32 = 500.0; // RMS threshold for energy-based VAD
|
||||
pub const VAD_NNNOISELESS_THRESHOLD: f32 = 0.5; // probability threshold for nnnoiseless
|
||||
pub const VAD_ENERGY_THRESHOLD: f32 = 100.0; // RMS threshold for energy-based VAD
|
||||
pub const VAD_NNNOISELESS_THRESHOLD: f32 = 0.8; // probability threshold for nnnoiseless
|
||||
pub const VAD_SILENCE_FRAMES: u32 = 15; // frames of silence before speech end (~480ms)
|
||||
|
||||
// gain normalizer settings
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ settings-stt-engine = Speech recognition
|
|||
settings-intent-engine = Intent recognition
|
||||
settings-intent-engine-desc = Select neural network for command recognition.
|
||||
settings-noise-suppression = Noise suppression
|
||||
settings-noise-suppression-desc = Reduces background noise.
|
||||
settings-noise-suppression-desc = Reduces background noise. May negatively affect recognition.
|
||||
settings-vad = Voice detection (VAD)
|
||||
settings-vad-desc = Skips silence, saves CPU resources.
|
||||
settings-gain-normalizer = Gain normalizer
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ settings-stt-engine = Распознавание речи
|
|||
settings-intent-engine = Определение намерения
|
||||
settings-intent-engine-desc = Выберите нейросеть для распознавания команд.
|
||||
settings-noise-suppression = Шумоподавление
|
||||
settings-noise-suppression-desc = Уменьшает фоновый шум.
|
||||
settings-noise-suppression-desc = Уменьшает фоновый шум. Может негативно влиять на распознавание.
|
||||
settings-vad = Определение голоса (VAD)
|
||||
settings-vad-desc = Пропускает тишину, экономит ресурсы CPU.
|
||||
settings-gain-normalizer = Нормализация громкости
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ settings-stt-engine = Розпізнавання мовлення
|
|||
settings-intent-engine = Визначення наміру
|
||||
settings-intent-engine-desc = Виберіть нейромережу для розпізнавання команд.
|
||||
settings-noise-suppression = Шумозаглушення
|
||||
settings-noise-suppression-desc = Зменшує фоновий шум.
|
||||
settings-noise-suppression-desc = Зменшує фоновий шум. Може негативно впливати на розпізнавання.
|
||||
settings-vad = Визначення голосу (VAD)
|
||||
settings-vad-desc = Пропускає тишу, економить ресурси CPU.
|
||||
settings-gain-normalizer = Нормалізація гучності
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ pub mod ipc;
|
|||
|
||||
pub mod voices;
|
||||
|
||||
pub mod audio_buffer;
|
||||
|
||||
// shared statics
|
||||
// pub static APP_DIR: Lazy<PathBuf> = Lazy::new(|| std::env::current_dir().unwrap());
|
||||
pub static APP_DIR: Lazy<PathBuf> = Lazy::new(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue