Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(voice): probe STT/TTS installs via find_spec so the badge is right on the first cold-boot check (#78)

purple35c99550ad1d
diff --git a/src-tauri/src/commands/tts.rs b/src-tauri/src/commands/tts.rs
index 14c69e2d..38608c3f 100644
--- a/src-tauri/src/commands/tts.rs
+++ b/src-tauri/src/commands/tts.rs
@@ -54,7 +54,7 @@ pub fn piper_voice_paths(app: &tauri::AppHandle, voice: &str) -> Result<(PathBuf
))
}
-/// Whether neural TTS is usable: `import piper` succeeds AND the DEFAULT voice
+/// Whether neural TTS is usable: the `piper` package is installed AND a voice
/// model is present. The Settings badge + the chat SpeakerButton gate on this.
#[tauri::command]
pub fn tts_status(state: State<'_, AppState>, app: tauri::AppHandle) -> Result<serde_json::Value, String> {
@@ -63,7 +63,15 @@ pub fn tts_status(state: State<'_, AppState>, app: tauri::AppHandle) -> Result<s
let mut piper_importable = false;
if !python.is_empty() && crate::python::is_real_python(&python) {
let mut cmd = Command::new(&python);
- cmd.args(["-c", "import piper"]).stdout(Stdio::null()).stderr(Stdio::null());
+ // find_spec, not a full `import piper`, so the badge stays a cheap
+ // installability check that can't stall on a heavy import (mirrors
+ // whisper_package_installed — see #78).
+ cmd.args([
+ "-c",
+ "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('piper') else 1)",
+ ])
+ .stdout(Stdio::null())
+ .stderr(Stdio::null());
#[cfg(target_os = "windows")]
cmd.creation_flags(CREATE_NO_WINDOW);
piper_importable = cmd.output().map(|o| o.status.success()).unwrap_or(false);
diff --git a/src-tauri/src/commands/whisper.rs b/src-tauri/src/commands/whisper.rs
index a0df601a..90f45e9b 100644
--- a/src-tauri/src/commands/whisper.rs
+++ b/src-tauri/src/commands/whisper.rs
@@ -183,7 +183,17 @@ fn whisper_package_installed(state: &AppState) -> bool {
return false;
}
let mut cmd = Command::new(&python);
- cmd.args(["-c", "import faster_whisper"])
+ // Probe INSTALLABILITY with importlib.find_spec, NOT a full
+ // `import faster_whisper`. The real import pulls in ctranslate2 / onnxruntime
+ // / av and takes ~8 s warm (longer with a cold OS file cache), which on the
+ // first status check right after a cold relaunch blew past the cap below and
+ // made STT read as "not installed" until the next check — the #78 symptom,
+ // softened but not gone. find_spec answers "is the package present" in about
+ // 100 ms with no heavy import, so the badge is right on the very first probe.
+ cmd.args([
+ "-c",
+ "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('faster_whisper') else 1)",
+ ])
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null());
@@ -193,8 +203,8 @@ fn whisper_package_installed(state: &AppState) -> bool {
Ok(c) => c,
Err(_) => return false,
};
- // An ABSENT package fails in well under a second; a present one loads
- // ctranslate2 (a few seconds cold). 10 s cap so status never hangs.
+ // find_spec returns in well under a second; the cap is kept purely so a
+ // wedged interpreter can never hang the status call.
for _ in 0..100 {
match child.try_wait() {
Ok(Some(status)) => return status.success(),