Your first listener
Listener is the batteries-included API. It opens a microphone, converts its audio to the format the model expects, owns a Detector, and suppresses immediate repeats.
1. Add the code
Section titled “1. Add the code”use micro_wakeword::Listener;
fn main() -> Result<(), Box<dyn std::error::Error>> { let mut listener = Listener::from_config("models/wake-word.json")?;
println!( "Listening for {}", listener.detector().config().wake_word );
while let Some(detection) = listener.next_detection()? { println!( "Detected {} ({:.1}%)", detection.wake_word, detection.probability * 100.0 ); }
Ok(())}2. Run in release mode
Section titled “2. Run in release mode”cargo run --releaseSpeak the model’s wake phrase. A detection contains:
wake_word: the label from your configuration;probability: the smoothed model score from0.0to1.0.
What each call does
Section titled “What each call does”Listener::from_config(...)parses and validates JSON, resolves its model path, loads TensorFlow Lite, opens the current default input, and starts the audio stream.next_detection()waits for microphone audio and processes it until a detection occurs or the stream ends.- The listener applies its default one-second cooldown after a detection.
- The
while letloop continues untilnext_detection()returnsOk(None). Microphone failures are returned as errors rather than silently hidden.
Configure it with a builder
Section titled “Configure it with a builder”use std::time::Duration;use micro_wakeword::Listener;
# fn run() -> micro_wakeword::Result<()> {let mut listener = Listener::config_builder("models/wake-word.json")? .device("USB Mic") .cooldown(Duration::from_secs_f64(0.5)) .build()?;# Ok(())The device can be its numeric index, its exact name, or an unambiguous case-insensitive part of its name.