Tighten wake detection and keep short commands quiet
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
Reference in New Issue
Block a user