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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(tts): the green check vouched for a voice that could not speak (#77)
purplee21fa69ad7cf
diff --git a/src-tauri/src/commands/tts.rs b/src-tauri/src/commands/tts.rsindex cc305e53..85bc3667 100644--- a/src-tauri/src/commands/tts.rs+++ b/src-tauri/src/commands/tts.rs@@ -54,10 +54,29 @@ pub fn piper_voice_paths(app: &tauri::AppHandle, voice: &str) -> Result<(PathBuf))}+/// A voice is only usable when BOTH halves are on disk and non-empty. Piper+/// needs the config next to the model, and `synthesize` refuses without it —+/// but the badge, the picker and the download check all used to look at the+/// `.onnx` alone. A voice whose config never landed therefore read as installed+/// everywhere while every read-aloud failed with `no_voice` and fell back to the+/// system voice: green check, chosen voice, still Microsoft George (#77).+pub(crate) fn voice_is_complete(app: &tauri::AppHandle, voice: &str) -> bool {+ let (onnx, config) = match piper_voice_paths(app, voice) {+ Ok(p) => p,+ Err(_) => return false,+ };+ let nonempty = |p: &PathBuf| std::fs::metadata(p).map(|m| m.len() > 0).unwrap_or(false);+ nonempty(&onnx) && nonempty(&config)+}+/// 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> {+pub fn tts_status(+ voice: Option<String>,+ state: State<'_, AppState>,+ app: tauri::AppHandle,+) -> Result<serde_json::Value, String> {let python = crate::commands::install::resolve_lu_python(state.inner());let mut piper_importable = false;@@ -77,19 +96,15 @@ pub fn tts_status(state: State<'_, AppState>, app: tauri::AppHandle) -> Result<spiper_importable = cmd.output().map(|o| o.status.success()).unwrap_or(false);}- // Ready if ANY voice model is present, not just the hardcoded default- // (#77, ElBiggus): a user who downloaded a different voice than- // en_US-lessac-medium had the badge read "not installed" and every read- // fell back to the Windows SAPI voice.- let voice_ready = piper_voices_dir(&app)- .ok()- .and_then(|dir| std::fs::read_dir(&dir).ok())- .map(|entries| {- entries- .flatten()- .any(|e| e.file_name().to_string_lossy().ends_with(".onnx"))- })- .unwrap_or(false);+ // Ready if the SELECTED voice is complete — or, when the caller names none,+ // if any complete voice exists. Checking "any .onnx anywhere" (#77, first+ // pass) still lied twice over: a half-downloaded voice counted, and a user+ // who picked voice B while only voice A was on disk got a green badge for a+ // voice that could never speak.+ let voice_ready = match voice.as_deref().filter(|v| is_valid_voice(v)) {+ Some(v) => voice_is_complete(&app, v),+ None => installed_voice_ids(&app).iter().any(|v| voice_is_complete(&app, v)),+ };Ok(serde_json::json!({"available": piper_importable && voice_ready,@@ -102,9 +117,19 @@ pub fn tts_status(state: State<'_, AppState>, app: tauri::AppHandle) -> Result<s/// `*.onnx` models). The Settings picker marks these as installed.#[tauri::command]pub fn installed_piper_voices(app: tauri::AppHandle) -> Result<Vec<String>, String> {- let dir = match piper_voices_dir(&app) {+ // Only voices that can actually speak — a model without its config would+ // otherwise show up as installed and then fail at synthesis time.+ Ok(installed_voice_ids(&app)+ .into_iter()+ .filter(|v| voice_is_complete(&app, v))+ .collect())+}++/// Every voice id that has a `.onnx` in the voices dir, complete or not.+fn installed_voice_ids(app: &tauri::AppHandle) -> Vec<String> {+ let dir = match piper_voices_dir(app) {Ok(d) => d,- Err(_) => return Ok(vec![]),+ Err(_) => return vec![],};let mut out = vec![];if let Ok(entries) = std::fs::read_dir(&dir) {@@ -115,7 +140,7 @@ pub fn installed_piper_voices(app: tauri::AppHandle) -> Result<Vec<String>, Stri}}}- Ok(out)+ out}/// Download a specific Piper voice model into the piper_voices dir. Blocking —@@ -154,10 +179,20 @@ pub fn download_voice(if !output.status.success() {return Err(format!("voice download failed: {}", String::from_utf8_lossy(&output.stderr)));}- let (onnx, _) = piper_voice_paths(&app, &voice)?;+ // Verify BOTH halves. The downloader exiting 0 with only the model on disk+ // is the state that made the badge green while synthesis kept failing (#77).+ let (onnx, config) = piper_voice_paths(&app, &voice)?;if !onnx.exists() {return Err("voice download reported success but the model is missing".to_string());}+ if !voice_is_complete(&app, &voice) {+ let _ = std::fs::remove_file(&onnx);+ let _ = std::fs::remove_file(&config);+ return Err(format!(+ "the '{}' voice downloaded incomplete (its config file is missing) — try again",+ voice+ ));+ }Ok(serde_json::json!({ "ok": true, "voice": voice }))}diff --git a/src/api/voice.ts b/src/api/voice.tsindex ec55718f..08997e0a 100644--- a/src/api/voice.ts+++ b/src/api/voice.ts@@ -292,17 +292,20 @@ export async function synthesizeCloud(text: string, voice?: string, signal?: Abolet ttsChecked = false;let ttsAvailableFlag = false;+let ttsCheckedVoice: string | undefined;-export async function checkTtsAvailable(): Promise<{ available: boolean; piper?: boolean; voice?: boolean }> {+/** Probe neural TTS. Pass the SELECTED voice — readiness is per voice: having+ * some other voice on disk says nothing about the one that is about to speak. */+export async function checkTtsAvailable(voice?: string): Promise<{ available: boolean; piper?: boolean; voice?: boolean }> {try {- if (isTauri()) return await backendCall("tts_status");+ if (isTauri()) return await backendCall("tts_status", { voice });return { available: false };} catch {return { available: false };}}-export async function initTtsCheck(): Promise<boolean> {+export async function initTtsCheck(voice?: string): Promise<boolean> {// Cache only a POSITIVE result. A negative probe at boot is frequently a// race — resolve_lu_python / the ComfyUI venv may not be ready when App.tsx// fires this — and caching `false` would stick for the whole session, so@@ -310,21 +313,24 @@ export async function initTtsCheck(): Promise<boolean> {// never spoke at all (#77, ElBiggus). On a negative we leave ttsChecked// false so the next caller (the lazy re-probe in useVoice, or Settings)// gets a fresh probe instead of the stale miss.- if (ttsChecked && ttsAvailableFlag) return ttsAvailableFlag;+ // The cache is per voice: a positive for the voice that was selected earlier+ // must not vouch for the one the user switched to.+ if (ttsChecked && ttsAvailableFlag && ttsCheckedVoice === voice) return ttsAvailableFlag;try {- ttsAvailableFlag = (await checkTtsAvailable()).available;+ ttsAvailableFlag = (await checkTtsAvailable(voice)).available;} catch {ttsAvailableFlag = false;}ttsChecked = ttsAvailableFlag;+ ttsCheckedVoice = voice;return ttsAvailableFlag;}// Force a fresh probe (after the in-app install, or when a Speaker button mounts// while neural TTS still shows unavailable).-export async function recheckTtsAvailable(): Promise<boolean> {+export async function recheckTtsAvailable(voice?: string): Promise<boolean> {ttsChecked = false;- return initTtsCheck();+ return initTtsCheck(voice);}/** Synthesize text to a playable WAV data URL via a local Piper voice. */diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex 3c6aa327..36b02ec0 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -913,7 +913,7 @@ export function SettingsPage() {const refreshTts = () => {setTtsLoading(true)- return checkTtsAvailable()+ return checkTtsAvailable(voiceSettings.piperVoice).then((s) => {setTtsStatus(s)// Same as STT: drive the read-aloud button availability from this probediff --git a/src/hooks/useVoice.ts b/src/hooks/useVoice.tsindex f53f1b7f..fc139dce 100644--- a/src/hooks/useVoice.ts+++ b/src/hooks/useVoice.ts@@ -176,7 +176,7 @@ export function useVoice() {// Re-probe neural TTS on demand (after install) and sync the store.const recheckTts = useCallback(async (): Promise<boolean> => {- const ok = await recheckTtsAvailable();+ const ok = await recheckTtsAvailable(store.piperVoice);store.setTtsAvailable(ok);return ok;}, [store]);@@ -348,7 +348,7 @@ export function useVoice() {let piperReady = store.ttsAvailable;if (!piperReady && lazyTtsReprobes < MAX_LAZY_TTS_REPROBES && store.ttsMode !== "external") {lazyTtsReprobes++;- piperReady = await recheckTtsAvailable();+ piperReady = await recheckTtsAvailable(store.piperVoice);if (stopped()) return;if (piperReady) store.setTtsAvailable(true);}