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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Audio capture (microphone input) via cpal.
//!
//! Provides `AudioCapture` for streaming PCM audio from the default
//! input device at 16 kHz, 16-bit, mono.
/// Audio capture configuration.
#[derive(Debug, Clone)]
pub struct CaptureConfig {
pub sample_rate: u32,
pub channels: u16,
pub chunk_size: u32,
pub device_name: Option<String>,
}
impl Default for CaptureConfig {
fn default() -> Self {
Self {
sample_rate: 16000,
channels: 1,
chunk_size: 512,
device_name: None,
}
}
}
/// Microphone audio capture stream.
///
/// Wraps cpal input stream. Currently a stub -- real cpal integration
/// will be added after VP (pre-implementation validation) completes.
pub struct AudioCapture {
config: CaptureConfig,
active: bool,
}
impl AudioCapture {
/// Create a new audio capture with the given configuration.
pub fn new(config: CaptureConfig) -> Self {
Self { config, active: false }
}
/// Start capturing audio.
pub fn start(&mut self) -> Result<(), String> {
// Stub: real cpal stream creation goes here after VP
self.active = true;
tracing::info!(
sample_rate = self.config.sample_rate,
channels = self.config.channels,
"Audio capture started (stub)"
);
Ok(())
}
/// Stop capturing audio.
pub fn stop(&mut self) {
self.active = false;
tracing::info!("Audio capture stopped");
}
/// Check if capture is active.
pub fn is_active(&self) -> bool {
self.active
}
/// Get the capture configuration.
pub fn config(&self) -> &CaptureConfig {
&self.config
}
}