A free, open source, and extensible speech-to-text application that works completely offline.
Load the VAD when model loads in parallel (#1177)
Jackson7ed8a558f279
diff --git a/src-tauri/src/actions.rs b/src-tauri/src/actions.rsindex 47503241..3219caf9 100644--- a/src-tauri/src/actions.rs+++ b/src-tauri/src/actions.rs@@ -368,14 +368,21 @@ impl ShortcutAction for TranscribeAction {// Load model in the backgroundlet tm = app.state::<Arc<TranscriptionManager>>();+ let rm = app.state::<Arc<AudioRecordingManager>>();++ // Load ASR model and VAD model in paralleltm.initiate_model_load();+ let rm_clone = Arc::clone(&rm);+ std::thread::spawn(move || {+ if let Err(e) = rm_clone.preload_vad() {+ debug!("VAD pre-load failed: {}", e);+ }+ });let binding_id = binding_id.to_string();change_tray_icon(app, TrayIconState::Recording);show_recording_overlay(app);- let rm = app.state::<Arc<AudioRecordingManager>>();-// Get the microphone mode to determine audio feedback timinglet settings = get_settings(app);let is_always_on = settings.always_on_microphone;diff --git a/src-tauri/src/managers/audio.rs b/src-tauri/src/managers/audio.rsindex b3378b72..24dd04fc 100644--- a/src-tauri/src/managers/audio.rs+++ b/src-tauri/src/managers/audio.rs@@ -263,6 +263,25 @@ impl AudioRecordingManager {}}+ pub fn preload_vad(&self) -> Result<(), anyhow::Error> {+ let mut recorder_opt = self.recorder.lock().unwrap();+ if recorder_opt.is_none() {+ let vad_path = self+ .app_handle+ .path()+ .resolve(+ "resources/models/silero_vad_v4.onnx",+ tauri::path::BaseDirectory::Resource,+ )+ .map_err(|e| anyhow::anyhow!("Failed to resolve VAD path: {}", e))?;+ *recorder_opt = Some(create_audio_recorder(+ vad_path.to_str().unwrap(),+ &self.app_handle,+ )?);+ }+ Ok(())+ }+pub fn start_microphone_stream(&self) -> Result<(), anyhow::Error> {let mut open_flag = self.is_open.lock().unwrap();if *open_flag {@@ -276,23 +295,6 @@ impl AudioRecordingManager {let mut did_mute_guard = self.did_mute.lock().unwrap();*did_mute_guard = false;- let vad_path = self- .app_handle- .path()- .resolve(- "resources/models/silero_vad_v4.onnx",- tauri::path::BaseDirectory::Resource,- )- .map_err(|e| anyhow::anyhow!("Failed to resolve VAD path: {}", e))?;- let mut recorder_opt = self.recorder.lock().unwrap();-- if recorder_opt.is_none() {- *recorder_opt = Some(create_audio_recorder(- vad_path.to_str().unwrap(),- &self.app_handle,- )?);- }-// Get the selected device from settings, considering clamshell modelet settings = get_settings(&self.app_handle);let selected_device = self.get_effective_microphone_device(&settings);@@ -309,6 +311,10 @@ impl AudioRecordingManager {}}+ // Ensure VAD is loaded if it wasn't for whatever reason+ self.preload_vad()?;++ let mut recorder_opt = self.recorder.lock().unwrap();if let Some(rec) = recorder_opt.as_mut() {rec.open(selected_device).map_err(|e| anyhow::anyhow!("Failed to open recorder: {}", e))?;