1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Channel-neutral microphone listener.
use crate::;
use async_trait;
use mpsc;
/// A `Listener` owns the microphone, runs VAD, drives STT, and emits a stream
/// of [`VoiceEvent`]s.
///
/// Channels (CLI, Bevy GUI) consume the trait, not concrete impls — that
/// keeps the audio capture / VAD / STT pipeline pluggable and lets us swap
/// providers without touching the channels.
///
/// # Lifecycle
///
/// 1. Construct with a [`VoiceConfig`].
/// 2. Call [`Listener::start`] to acquire the device and begin emitting.
/// 3. Drain the returned receiver until you want to stop.
/// 4. Call [`Listener::stop`] to release the device.
///
/// # Cancellation and backpressure
///
/// The returned [`mpsc::Receiver`] is bounded, which gives natural
/// backpressure: if the consumer falls behind, the producer side either
/// blocks (preferred) or drops the oldest event (configurable per impl).
/// Implementations should document their drop policy.
///
/// End-of-stream is signalled by the sender being dropped (the receiver's
/// `recv()` will return `None`). This happens when:
/// - the caller drops the receiver (consumer-driven cancellation),
/// - the caller invokes [`Listener::stop`] (graceful shutdown),
/// - the underlying audio device disappears (error path — the impl should
/// log and emit a final event, then drop).