Skip to main content

speech_prep/
types.rs

1//! Core types for audio processing.
2
3/// A chunk of audio data with metadata.
4#[derive(Debug, Clone)]
5pub struct AudioChunk {
6    /// Raw PCM samples (mono, f32).
7    pub data: Vec<f32>,
8    /// Chunk sequence number.
9    pub chunk_id: u64,
10    /// Timestamp in seconds from stream start.
11    pub timestamp_secs: f64,
12    /// Sample rate in Hz.
13    pub sample_rate: u32,
14}
15
16impl AudioChunk {
17    pub fn new(data: Vec<f32>, chunk_id: u64, timestamp_secs: f64, sample_rate: u32) -> Self {
18        Self {
19            data,
20            chunk_id,
21            timestamp_secs,
22            sample_rate,
23        }
24    }
25
26    pub fn duration_secs(&self) -> f64 {
27        if self.sample_rate == 0 {
28            return 0.0;
29        }
30        self.data.len() as f64 / self.sample_rate as f64
31    }
32}