Tighten wake detection and keep short commands quiet

This commit is contained in:
2026-11-10 22:35:13 +03:00
parent 6b483c9c08
commit a27589447e
20 changed files with 833 additions and 92 deletions
+44
View File
@@ -0,0 +1,44 @@
use micro_wakeword::{AUDIO_BLOCK_SAMPLES, Detector};
use std::io::{self, Read, Write};
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let model = PathBuf::from(
std::env::args_os()
.nth(1)
.ok_or("usage: alice-wake-helper MODEL")?,
);
let mut detector = Detector::builder(model)
.wake_word("Алиса")
.probability_cutoff(0.90)
.sliding_window_size(6)
.build()?;
let mut input = io::stdin().lock();
let mut output = io::stdout().lock();
let mut bytes = [0; AUDIO_BLOCK_SAMPLES * 2];
let mut samples = [0; AUDIO_BLOCK_SAMPLES];
output.write_all(&[0])?;
output.flush()?;
let mut opcode = [0];
while input.read(&mut opcode)? != 0 {
let detected = match opcode[0] {
0 => {
detector.reset()?;
false
}
1 => {
input.read_exact(&mut bytes)?;
for (sample, pair) in samples.iter_mut().zip(bytes.chunks_exact(2)) {
*sample = i16::from_le_bytes([pair[0], pair[1]]);
}
detector.process_audio(&samples)?.is_some()
}
_ => return Err("unknown wake helper command".into()),
};
output.write_all(&[u8::from(detected)])?;
output.flush()?;
}
Ok(())
}