#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProcessingState {
Idle,
Loading,
Transcribing,
Paused,
Completed,
Error,
}
#[derive(Debug, Clone)]
pub struct AudioVisualizationData {
pub samples: Vec<f32>,
pub is_speaking: bool,
pub transcript: String,
pub reset_requested: bool,
pub processing_state: ProcessingState,
pub processing_state_changed: std::time::Instant,
}
impl AudioVisualizationData {
pub fn with_capacity(capacity: usize) -> Self {
Self {
samples: Vec::with_capacity(capacity),
is_speaking: false,
transcript: String::new(),
reset_requested: false,
processing_state: ProcessingState::Idle,
processing_state_changed: std::time::Instant::now(),
}
}
pub fn clear_samples(&mut self) {
self.samples.clear();
}
pub fn update_transcript(&mut self, new_transcript: &str) {
self.transcript.clear();
self.transcript.push_str(new_transcript);
}
pub fn update_samples(&mut self, new_samples: &[f32]) {
self.samples.clear();
self.samples.extend_from_slice(new_samples);
}
pub fn set_processing_state(&mut self, state: ProcessingState) {
if self.processing_state != state {
self.processing_state = state;
self.processing_state_changed = std::time::Instant::now();
}
}
pub fn is_processing(&self) -> bool {
matches!(
self.processing_state,
ProcessingState::Loading | ProcessingState::Transcribing | ProcessingState::Paused
)
}
pub fn processing_state_duration(&self) -> std::time::Duration {
self.processing_state_changed.elapsed()
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum BackendStatusState {
Ready,
Loading(String),
Error(String),
}
#[derive(Debug, Clone)]
pub struct BackendStatus {
pub backend_name: String,
pub model_name: String,
pub state: BackendStatusState,
pub error_time: Option<std::time::Instant>,
pub download_progress: Option<f32>,
pub is_recording: bool,
pub recording_start: Option<std::time::Instant>,
}
impl BackendStatus {
pub fn new(backend_name: String, model_name: String) -> Self {
Self {
backend_name,
model_name,
state: BackendStatusState::Ready,
error_time: None,
download_progress: None,
is_recording: false,
recording_start: None,
}
}
}