Skip to main content

clawft_plugin/voice/
capture.rs

1//! Audio capture (microphone input) via cpal.
2//!
3//! Provides `AudioCapture` for streaming PCM audio from the default
4//! input device at 16 kHz, 16-bit, mono.
5
6/// Audio capture configuration.
7#[derive(Debug, Clone)]
8pub struct CaptureConfig {
9    pub sample_rate: u32,
10    pub channels: u16,
11    pub chunk_size: u32,
12    pub device_name: Option<String>,
13}
14
15impl Default for CaptureConfig {
16    fn default() -> Self {
17        Self {
18            sample_rate: 16000,
19            channels: 1,
20            chunk_size: 512,
21            device_name: None,
22        }
23    }
24}
25
26/// Microphone audio capture stream.
27///
28/// Wraps cpal input stream. Currently a stub -- real cpal integration
29/// will be added after VP (pre-implementation validation) completes.
30pub struct AudioCapture {
31    config: CaptureConfig,
32    active: bool,
33}
34
35impl AudioCapture {
36    /// Create a new audio capture with the given configuration.
37    pub fn new(config: CaptureConfig) -> Self {
38        Self { config, active: false }
39    }
40
41    /// Start capturing audio.
42    pub fn start(&mut self) -> Result<(), String> {
43        // Stub: real cpal stream creation goes here after VP
44        self.active = true;
45        tracing::info!(
46            sample_rate = self.config.sample_rate,
47            channels = self.config.channels,
48            "Audio capture started (stub)"
49        );
50        Ok(())
51    }
52
53    /// Stop capturing audio.
54    pub fn stop(&mut self) {
55        self.active = false;
56        tracing::info!("Audio capture stopped");
57    }
58
59    /// Check if capture is active.
60    pub fn is_active(&self) -> bool {
61        self.active
62    }
63
64    /// Get the capture configuration.
65    pub fn config(&self) -> &CaptureConfig {
66        &self.config
67    }
68}