//! Application state holding shared ML models. use std::sync::Arc; use tokio::sync::Mutex; use crate::listen::{DiarizationConfig, ParakeetTDT, Sortformer}; /// Shared application state containing ML models. /// /// Models are wrapped in `Mutex` for thread-safe mutable access during inference. pub struct AppState { /// Speech-to-text model (Parakeet) pub parakeet: Mutex, /// Speaker diarization model (Sortformer) pub sortformer: Mutex, } impl AppState { /// Load all ML models from the specified directories. /// /// # Arguments /// * `parakeet_model_dir` - Path to the Parakeet STT model directory /// * `sortformer_model_path` - Path to the Sortformer diarization model file pub fn new( parakeet_model_dir: &str, sortformer_model_path: &str, ) -> Result> { let parakeet = ParakeetTDT::from_pretrained(parakeet_model_dir, None)?; let sortformer = Sortformer::with_config( sortformer_model_path, None, DiarizationConfig::callhome(), )?; Ok(Self { parakeet: Mutex::new(parakeet), sortformer: Mutex::new(sortformer), }) } } /// Type alias for the shared application state. pub type SharedState = Arc;