Skip to main content

clawft_plugin/voice/
playback.rs

1//! Audio playback (speaker output) via cpal.
2
3/// Audio playback configuration.
4#[derive(Debug, Clone)]
5pub struct PlaybackConfig {
6    pub sample_rate: u32,
7    pub channels: u16,
8    pub device_name: Option<String>,
9}
10
11impl Default for PlaybackConfig {
12    fn default() -> Self {
13        Self {
14            sample_rate: 16000,
15            channels: 1,
16            device_name: None,
17        }
18    }
19}
20
21/// Speaker audio playback stream.
22///
23/// Wraps cpal output stream. Currently a stub.
24pub struct AudioPlayback {
25    config: PlaybackConfig,
26    active: bool,
27}
28
29impl AudioPlayback {
30    pub fn new(config: PlaybackConfig) -> Self {
31        Self { config, active: false }
32    }
33
34    pub fn start(&mut self) -> Result<(), String> {
35        self.active = true;
36        tracing::info!("Audio playback started (stub)");
37        Ok(())
38    }
39
40    pub fn stop(&mut self) {
41        self.active = false;
42        tracing::info!("Audio playback stopped");
43    }
44
45    pub fn is_active(&self) -> bool {
46        self.active
47    }
48
49    pub fn config(&self) -> &PlaybackConfig {
50        &self.config
51    }
52}