use std::any::Any;
use std::sync::Arc;
pub trait CustomFrame: Any + Send + Sync + std::fmt::Debug {
fn kind(&self) -> &'static str;
fn as_any(&self) -> &dyn Any;
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct AudioFormat {
pub sample_rate: u32,
pub channels: u16,
}
impl AudioFormat {
pub fn new(sample_rate: u32, channels: u16) -> Self {
Self { sample_rate, channels }
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct AudioChunk {
pub samples: Arc<[f32]>,
pub format: AudioFormat,
}
impl AudioChunk {
pub fn new(samples: Arc<[f32]>, format: AudioFormat) -> Self {
Self { samples, format }
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Direction {
Down,
Up,
}
#[derive(Clone, Debug)]
pub enum SystemFrame {
Start,
Stop,
Interrupt,
SpeechStarted,
SpeechStopped,
Error {
message: Arc<str>,
fatal: bool,
},
}
#[derive(Clone, Debug)]
pub enum DataFrame {
InputAudio {
bytes: Arc<[u8]>,
sample_rate: u32,
num_channels: u16,
},
Transcript(Arc<str>),
Audio(AudioChunk),
Custom(Arc<dyn CustomFrame>),
}
impl DataFrame {
pub fn survives_flush(&self) -> bool {
matches!(self, DataFrame::InputAudio { .. })
}
}