From 04c88e51d1826ae90494195550c82e8e076372f8 Mon Sep 17 00:00:00 2001 From: eddybean <38001995+eddybean@users.noreply.github.com> Date: Sat, 28 Nov 2026 21:58:04 +0900 Subject: [PATCH] Make model downloads explicit with visible progress; starting never downloads (D-59) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - resolve_model looks catalog names (NAME or NAME:TYPE) up in `speech models --json` and fails with a message pointing to the catalog when the file is not fetched, instead of running `speech pull` silently inside the engine start. - The catalog dialog lists Irodori-TTS v4.1 Small and v4 Large (Gemma terms, consent), and fills speechPull models' variants from speech.cpp (sizes, VRAM estimate, fetched). - The モデル screen offers only fetched Irodori models, warns about a missing one and disables its start; the status bar shows running downloads; starts show 準備中… and a second start is ignored. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- assets/models/catalog.json | 50 ++++++++++++++ docs/deviations.md | 17 ++++- docs/engine-protocol.md | 2 +- src-tauri/src/commands.rs | 26 +++++-- src-tauri/src/downloads.rs | 69 +++++++++++++++++++ src-tauri/src/tools.rs | 60 +++++++++++++--- src/app/Rail.tsx | 7 +- src/app/StatusBar.test.tsx | 41 ++++++++++- src/app/StatusBar.tsx | 33 ++++++++- src/features/models/CatalogDialog.tsx | 19 +++--- src/features/models/ModelManager.test.tsx | 60 +++++++++++++++- src/features/models/ModelManager.tsx | 83 +++++++++++++++++------ src/lib/ipc.ts | 2 + src/lib/text.ts | 8 +++ src/lib/types.ts | 2 + src/store/app.test.ts | 17 +++++ src/store/app.ts | 14 +++- 18 files changed, 454 insertions(+), 58 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 11f16fe..78e29c8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -48,7 +48,7 @@ VS_SPEECH_EXE=.engine/speech.exe VS_DRAMA_MODEL=path/to/Drama-35B-A3B-Japanese-v ## Architecture -**Engine process.** `engine::EngineSupervisor` keeps one resident `speech worker ` child process and talks JSON Lines over stdin/stdout (protocol 4; stdout carries only the protocol, logs go to stderr). It handles `synthesize` (streams base64 PCM `chunk`s), `add_voice`, `count_tokens`, `info` and `cancel`. Switching models stops one worker and starts the next. `speech voice`, `speech asr` and `speech pull` run as short-lived processes. Model catalog names (e.g. `irodori-tts-mf`) are resolved to file paths with `speech pull` before use (D-02). The protocol details and measurements are in `docs/engine-protocol.md`: read it before touching `engine/` or the adapters. +**Engine process.** `engine::EngineSupervisor` keeps one resident `speech worker ` child process and talks JSON Lines over stdin/stdout (protocol 4; stdout carries only the protocol, logs go to stderr). It handles `synthesize` (streams base64 PCM `chunk`s), `add_voice`, `count_tokens`, `info` and `cancel`. Switching models stops one worker and starts the next. `speech voice`, `speech asr`, `speech models` and `speech pull` run as short-lived processes. Model catalog names (`irodori-tts-mf`, or `NAME:TYPE`) are resolved to file paths from `speech models --json` before use (D-02); a model that is not fetched is an error, never a silent download: `speech pull` runs only from the catalog dialog's download, with progress (D-59). The protocol details and measurements are in `docs/engine-protocol.md`: read it before touching `engine/` or the adapters. **Model adapters** (`src-tauri/src/models/`). Each model declares `Capabilities` (tag syntax brackets/emoji, sample rate, multi-speaker support, and so on) and an `OptionSpec` schema, and turns a `LineRequest` into a worker request. The worker rejects any member it does not know (`invalid_argument`), so an adapter must send only options its model takes. The UI builds its option forms from the schema (`features/models/OptionForm.tsx`). Irodori strips `[..]` cues and `<|speaker:N|>` before sending (D-04). The tag palettes are `assets/tags/*.json`; the download catalog is `assets/models/catalog.json`. diff --git a/assets/models/catalog.json b/assets/models/catalog.json index 3dd678e..18712b9 100644 --- a/assets/models/catalog.json +++ b/assets/models/catalog.json @@ -95,6 +95,56 @@ } ] }, + { + "id": "irodori-tts", + "name": "Irodori-TTS v4.1 Small", + "task": "synthesis", + "adapter": "irodori", + "description": "Irodori-TTS の通常版(40 ステップ)。Small-MF より遅いが CFG で参照音声への寄せ方を調整できる。", + "source": { "kind": "speechPull", "name": "irodori-tts" }, + "license": { + "name": "MIT", + "url": "https://huggingface.co/sakasegawa/Irodori-TTS-v4.1-Small-GGUF", + "summary": "MIT License", + "requiresConsent": false + }, + "env": {}, + "device": "Vulkan0", + "defaultVariant": "f16", + "variants": [ + { + "id": "f16", + "label": "F16", + "vramBytes": 2632000000, + "files": [{ "name": "Irodori-TTS-859M-v4.1-F16.gguf", "size": 1905903936, "sha256": "", "role": "model" }] + } + ] + }, + { + "id": "irodori-tts-large", + "name": "Irodori-TTS v4 Large", + "task": "synthesis", + "adapter": "irodori", + "description": "Irodori-TTS の大型版(3.4B)。品質重視、Small より多くの VRAM と時間を使う。", + "source": { "kind": "speechPull", "name": "irodori-tts-large" }, + "license": { + "name": "Gemma Terms of Use", + "url": "https://ai.google.dev/gemma/terms", + "summary": "Gemma 利用規約に基づくモデルです。禁止用途ポリシー (Gemma Prohibited Use Policy) を含む規約に従って利用してください。", + "requiresConsent": true + }, + "env": {}, + "device": "Vulkan0", + "defaultVariant": "q8_0", + "variants": [ + { + "id": "q8_0", + "label": "Q8_0", + "vramBytes": 4800000000, + "files": [{ "name": "Irodori-TTS-3.4B-v4-Q8_0.gguf", "size": 3875154272, "sha256": "", "role": "model" }] + } + ] + }, { "id": "qwen3-asr-0.6b", "name": "Qwen3-ASR 0.6B(参照音声の自動書き起こし)", diff --git a/docs/deviations.md b/docs/deviations.md index 0d439b7..fb91324 100644 --- a/docs/deviations.md +++ b/docs/deviations.md @@ -21,7 +21,7 @@ They are listed under "Decisions pending" at the end. ### D-02 Model catalog names are resolved to file paths with `speech pull` before use 【変更】 - **What**: The profile's `irodori-tts-mf` and the ASR's `qwen3-asr-0.6b` are converted to a path with `speech pull NAME`, and every subcommand receives that path. - **Why**: When speech.exe was started from another program, passing a model name sometimes downloaded the existing model again. -- **Workaround / user impact**: None. On first use of a model that has not been fetched yet, the download runs (the model management dialog shows "not fetched"). +- **Workaround / user impact**: None. On first use of a model that has not been fetched yet, the download runs (the model management dialog shows "not fetched"). *Superseded by D-59: the path now comes from `speech models --json`, and a model that is not fetched is an error that points to the catalog dialog.* ### D-03 Irodori voices are also always turned into a `.voice.gguf` 【変更】 - **What**: The plan says Irodori can use a reference WAV directly. The implementation always makes a voice file first with `speech voice irodori-tts-mf ref.wav`. @@ -444,3 +444,18 @@ Requests: (1) a way to stop playback, (2) choosing a Drama-3 voice by text promp - Memory another program takes after the check is not seen. With the check off, nothing is measured, so after turning it on, the running engine's memory counts as used until the next start. - Not tried against a GPU that is really short of memory: the judgement is covered by unit tests (`memguard.rs`, `src/store/app.test.ts`). - **User impact**: Starting or switching a model when the device looks short of memory asks first (標準), or is refused (強). A start that fits is unchanged apart from the extra 0.15 s `speech devices` call. + +### D-59 Model downloads are explicit, with progress; starting never downloads 【変更(ユーザー要望)】 +- **What**: + - **No implicit download.** `tools::Speech::resolve_model` no longer runs `speech pull`: it looks the name (`NAME` or `NAME:TYPE`; TYPE defaults to the model's own `type`) up in `speech models --json` and returns the file's path when it is fetched, else the error "モデル「…」はまだダウンロードされていません。モデル画面の「カタログから入手」でダウンロードしてください". This covers the engine start, モデルを確認 and the ASR transcription. + - **One place to download.** The catalog dialog (カタログから入手) also lists Irodori-TTS v4.1 Small and v4 Large (`assets/models/catalog.json`; Large is under the Gemma Terms of Use and asks for consent). For `speechPull` models the variants are filled from `speech models --json` (`Catalog::merge_speech`): every quantization speech.cpp offers, its real size, a VRAM estimate by `memguard::estimate`, and whether it is already fetched (✓ 取得済). The download runs `speech pull NAME:TYPE` with the progress, cancel and free-space check it already had; `catalog_download` is now async. + - **The モデル screen** lists only the fetched Irodori files as quick picks (a non-default quantization as `NAME:TYPE`) and a "ほかの Irodori モデルを入手…" button. A profile whose catalog name is not fetched shows a warning with a button to the catalog, and its start button is disabled. The list is read again after a download finishes. + - **Progress everywhere.** The status bar shows the running download (`irodori-tts-large:q8_0 42%・残り 3分…`, plus how many more); clicking it opens the catalog dialog. + - **Preparing state.** `startEngine` sets `engineStarting` from the click until `engine_start` returns (path lookup, memory check, the confirmation); a second start meanwhile is ignored, the start buttons say 準備中… and are disabled, and the status bar says "… の起動を準備中…". +- **Why**: The user tried to get Irodori-TTS Large from the モデル screen: its button only set the name, and the download ran inside the engine start with no progress, no cancel and the engine still shown as stopped, so it looked frozen. Large was not in the catalog dialog at all. +- **Not done / limits**: + - The status bar names a download by its id (`model:variant`), not the display name. + - A typed catalog name that speech.cpp does not list fails with "speech.cpp のカタログに「…」がありません". + - Only the catalog's `speechPull` models get their variants from speech.cpp; other speech.cpp models (Qwen3-TTS and so on) are not offered, as no adapter uses them. +- **Checked** in the app (`npm run tauri dev`, driven over the WebView2 DevTools protocol, speech.cpp 0.11.2): the モデル screen lists the fetched `irodori-tts-mf` and `irodori-tts-large`; a profile set to the unfetched `irodori-tts` shows the warning with its start button disabled, and a start from the store fails in 44 ms with the message and no download. Starting `irodori-tts-mf` shows 準備中… (button disabled, a second start ignored), then 読み込み中…, then ready in 1.6 s. The catalog dialog lists every speech.cpp quantization of the three Irodori models and Qwen3-ASR with ✓ 取得済 where fetched; downloading Qwen3-ASR Q4_K (0.5 GB) showed its progress in the card and the status bar, ended with the ASR model set and the variant marked fetched; cancelling Irodori Small Q4_K at 10% left 中断 and a 再開 button. The fetched-recognition button read "プロファイルを作成", which was wrong: it now says 書き起こしモデルに設定. +- **User impact**: Picking or starting a model never starts a download. Downloads are started in the catalog dialog and their progress is visible from any screen. Profiles that name a model that was never fetched (for example a new Irodori profile on a fresh install) show a warning and need a download first. diff --git a/docs/engine-protocol.md b/docs/engine-protocol.md index edcf1a6..7401a51 100644 --- a/docs/engine-protocol.md +++ b/docs/engine-protocol.md @@ -53,7 +53,7 @@ ASR of the Drama-3 outputs returned the input text (tags removed), so synthesis 1. **Multi-speaker `<|speaker:N|>` in one request does not work with Drama-3-Japanese (this finetune).** With a 2-speaker cast voice and with `voice none`, with and without spaces/newlines, 4 seeds: the model always speaks only speaker 0's turn and stops with `stop: complete` (ASR hears only speaker 0's text). The base `fishaudio/drama-3` may differ (not tested: not downloaded). → Scene mode keeps the single-request `<|speaker:N|>` path (as planned, for models that can do it) but the UI warns, and offers **"per-line scene"**: each line is generated with its own cast voice, in order, and the result is concatenated with the lines' silences. This is the default for Drama-3-Japanese. -2. **Model names (`qwen3-asr-0.6b`, `irodori-tts-mf`) sometimes re-fetch** the file when speech.exe is started from another program (seen twice: the worker and `asr` printed `Fetching … checked its SHA-256` although the file was in the model folder). `speech pull NAME` answers in 30 ms with the path when it is there. → Speechorus resolves a catalog name to its path with `speech pull` once and passes **paths** to every subcommand. +2. **Model names (`qwen3-asr-0.6b`, `irodori-tts-mf`) sometimes re-fetch** the file when speech.exe is started from another program (seen twice: the worker and `asr` printed `Fetching … checked its SHA-256` although the file was in the model folder). `speech pull NAME` answers in 30 ms with the path when it is there. → Speechorus resolves a catalog name to its path once and passes **paths** to every subcommand. Since D-59 the path comes from `speech models --json` (`fetched`/`path` of the file, 40 ms), so an unfetched model is reported instead of downloaded; `speech pull NAME:TYPE` runs only for an explicit download. 3. `speech voice` does not need the GPU or the worker to stop; it runs as a short-lived process beside the worker. 4. The worker refuses unknown members, so `Drama3Adapter` drops `speed`/`instructions`/`steps` and `IrodoriAdapter` drops `top_k`/`top_p`/`temperature`/`max_seconds`/`experts_on_cpu` before sending. diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index cb75c89..2cbb522 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -542,10 +542,21 @@ pub struct CatalogView { pub running: Vec, } +/// The download catalog, with speech.cpp's own quantizations and fetched state for `speechPull` models (D-59). +async fn load_catalog(st: &AppState) -> crate::downloads::Catalog { + let mut catalog = crate::downloads::Catalog::load(&st.catalog_override); + let exe = st.exe(); + let env = BTreeMap::new(); + if let Ok(speech) = (Speech { exe: &exe, env: &env }).catalog().await { + catalog.merge_speech(&speech); + } + catalog +} + #[tauri::command] pub async fn catalog_list(app: AppHandle, st: State<'_, AppState>) -> R { - use crate::downloads::{recommend, Catalog}; - let catalog = Catalog::load(&st.catalog_override); + use crate::downloads::recommend; + let catalog = load_catalog(&st).await; let exe = st.exe(); let env = BTreeMap::new(); let devs = Speech { exe: &exe, env: &env }.devices().await.ok(); @@ -583,7 +594,7 @@ pub fn download_cancel(st: State<'_, AppState>, id: String) { /// Starts a catalog download in the background; progress and the result come as `download` events. /// On success a synthesis model gets a profile (created or replaced, and selected); a recognition model becomes the ASR model. #[tauri::command] -pub fn catalog_download( +pub async fn catalog_download( app: AppHandle, st: State<'_, AppState>, model_id: String, @@ -591,9 +602,9 @@ pub fn catalog_download( dest_dir: String, license_accepted: bool, ) -> R { - use crate::downloads::{Catalog, DownloadError, Progress, Source}; + use crate::downloads::{DownloadError, Progress, Source}; use std::sync::atomic::AtomicBool; - let catalog = Catalog::load(&st.catalog_override); + let catalog = load_catalog(&st).await; let (m, v) = catalog.find(&model_id, &variant_id).ok_or("カタログにないモデルです")?; if !v.supported { return Err(format!("{} は使えません: {}", v.label, v.unsupported_reason)); @@ -646,7 +657,10 @@ pub fn catalog_download( need: crate::downloads::gib(need + (1 << 30)), free: crate::downloads::gib(free), }), - _ => crate::downloads::speech_pull(&id2, &exe, name, cancel.clone(), on.clone()).await, + _ => { + let name = format!("{name}:{}", v.id); + crate::downloads::speech_pull(&id2, &exe, &name, cancel.clone(), on.clone()).await + } } } }; diff --git a/src-tauri/src/downloads.rs b/src-tauri/src/downloads.rs index a36ead2..0a4e7d4 100644 --- a/src-tauri/src/downloads.rs +++ b/src-tauri/src/downloads.rs @@ -72,6 +72,9 @@ pub struct Variant { pub unsupported_reason: String, pub vram_bytes: u64, pub files: Vec, + /// Already in speech.cpp's model folder (`speechPull` models only; filled in by [`Catalog::merge_speech`]). + #[serde(default)] + pub fetched: bool, } fn yes() -> bool { @@ -117,6 +120,47 @@ impl Catalog { .unwrap_or_else(|| Catalog::parse(BUILTIN_CATALOG).expect("built-in catalog")) } + /// Fills each `speechPull` model's variants from `speech models --json`: every quantization speech.cpp + /// offers, with its real size and whether it is already fetched (D-59). A model speech.cpp does not list + /// keeps the variants of catalog.json. + pub fn merge_speech(&mut self, speech: &serde_json::Value) { + use serde_json::Value; + let Some(list) = speech.get("models").and_then(Value::as_array) else { return }; + for m in &mut self.models { + let Source::SpeechPull { name } = &m.source else { continue }; + let Some(sm) = list.iter().find(|x| x.get("name").and_then(Value::as_str) == Some(name)) else { continue }; + let files = sm.get("files").and_then(Value::as_array).cloned().unwrap_or_default(); + let variants: Vec = files + .iter() + .filter_map(|f| { + let ty = f.get("type")?.as_str()?.to_string(); + let size = f.get("size")?.as_u64()?; + Some(Variant { + label: ty.to_uppercase(), + supported: true, + unsupported_reason: String::new(), + vram_bytes: crate::memguard::estimate(size), + files: vec![CatalogFile { + name: f.get("file").and_then(Value::as_str).unwrap_or_default().to_string(), + size, + sha256: f.get("sha256").and_then(Value::as_str).unwrap_or_default().to_string(), + role: "model".into(), + }], + fetched: f.get("fetched").and_then(Value::as_bool) == Some(true), + id: ty, + }) + }) + .collect(); + if variants.is_empty() { + continue; + } + if !variants.iter().any(|v| v.id == m.default_variant) { + m.default_variant = sm.get("type").and_then(Value::as_str).unwrap_or(&variants[0].id).to_string(); + } + m.variants = variants; + } + } + pub fn find(&self, model: &str, variant: &str) -> Option<(&CatalogModel, &Variant)> { let m = self.models.iter().find(|m| m.id == model)?; let v = m.variants.iter().find(|v| v.id == variant)?; @@ -533,6 +577,30 @@ mod tests { assert_eq!(c.find("qwen3-asr-0.6b", "q8_0").unwrap().0.task, "recognition"); } + #[test] + fn merges_speech_cpp_quantizations_and_fetched_state() { + let mut c = Catalog::parse(BUILTIN_CATALOG).unwrap(); + let speech = serde_json::json!({"models": [{ + "name": "irodori-tts-large", "type": "q8_0", + "files": [ + {"type": "q8_0", "file": "L-Q8_0.gguf", "size": 3_875_154_272u64, "sha256": "ab", "fetched": true}, + {"type": "q4_k", "file": "L-Q4_K.gguf", "size": 2_616_961_376u64, "sha256": "cd", "fetched": false} + ] + }]}); + let before = c.find("drama3-ja", "q4_k").unwrap().1.clone(); + c.merge_speech(&speech); + let (m, q8) = c.find("irodori-tts-large", "q8_0").unwrap(); + assert_eq!(m.default_variant, "q8_0"); + assert!(q8.fetched); + assert_eq!(q8.files[0].name, "L-Q8_0.gguf"); + assert_eq!(q8.vram_bytes, crate::memguard::estimate(3_875_154_272)); + assert!(!c.find("irodori-tts-large", "q4_k").unwrap().1.fetched); + assert_eq!(c.find("irodori-tts-large", "q4_k").unwrap().1.label, "Q4_K"); + // Hugging Face models and models speech.cpp does not list are left as they are. + assert_eq!(c.find("drama3-ja", "q4_k").unwrap().1, &before); + assert!(c.find("irodori-tts-mf", "f16").is_some()); + } + #[test] fn recommends_by_free_vram() { let c = Catalog::parse(BUILTIN_CATALOG).unwrap(); @@ -654,6 +722,7 @@ mod tests { supported: true, unsupported_reason: String::new(), vram_bytes: 0, + fetched: false, files: vec![CatalogFile { name: "huge.gguf".into(), size: u64::MAX / 4, diff --git a/src-tauri/src/tools.rs b/src-tauri/src/tools.rs index 6e51517..53a2a2b 100644 --- a/src-tauri/src/tools.rs +++ b/src-tauri/src/tools.rs @@ -1,4 +1,4 @@ -//! Short-lived `speech` subcommands: devices, info, pull, asr, voice. +//! Short-lived `speech` subcommands: devices, info, models, asr, voice. use std::collections::BTreeMap; use std::process::Stdio; @@ -18,6 +18,12 @@ pub enum ToolError { Failed(String, i32, String), #[error("speech の出力を読めません: {0}")] Output(String), + #[error( + "モデル「{0}」はまだダウンロードされていません。モデル画面の「カタログから入手」でダウンロードしてください" + )] + NotFetched(String), + #[error("speech.cpp のカタログに「{0}」がありません")] + Unknown(String), } pub struct Speech<'a> { @@ -76,19 +82,13 @@ impl Speech<'_> { self.json(&["models", "--json"]).await } - /// A `.gguf` path as it is; a catalog name becomes the path `speech pull` prints - /// (fetching it first when it is not in the model folder). + /// A `.gguf` path as it is; a catalog name (`NAME` or `NAME:TYPE`) becomes its file's path in the model + /// folder. A model that is not there is an error: downloads are started by the user (D-59), never here. pub async fn resolve_model(&self, model: &str) -> Result { if is_path(model) { return Ok(model.to_string()); } - let out = self.run(&["pull".into(), model.into()]).await?; - out.lines() - .rev() - .map(str::trim) - .find(|l| !l.is_empty()) - .map(str::to_owned) - .ok_or_else(|| ToolError::Output("speech pull printed no path".into())) + catalog_path(&self.catalog().await?, model) } /// The text of a recording, with the recognition model given (its path or catalog name). @@ -113,6 +113,26 @@ pub fn is_path(model: &str) -> bool { model.to_ascii_lowercase().ends_with(".gguf") || model.contains('/') || model.contains('\\') } +/// The file of `NAME[:TYPE]` in `speech models --json` output; TYPE defaults to the model's own `type`. +pub fn catalog_file<'a>(catalog: &'a Value, model: &str) -> Option<&'a Value> { + let (name, ty) = match model.split_once(':') { + Some((n, t)) => (n, Some(t)), + None => (model, None), + }; + let m = catalog.get("models")?.as_array()?.iter().find(|m| m.get("name").and_then(Value::as_str) == Some(name))?; + let ty = ty.or_else(|| m.get("type").and_then(Value::as_str))?; + m.get("files")?.as_array()?.iter().find(|f| f.get("type").and_then(Value::as_str) == Some(ty)) +} + +/// The path of a fetched catalog model, or why there is none. +pub fn catalog_path(catalog: &Value, model: &str) -> Result { + let f = catalog_file(catalog, model).ok_or_else(|| ToolError::Unknown(model.into()))?; + if f.get("fetched").and_then(Value::as_bool) != Some(true) { + return Err(ToolError::NotFetched(model.into())); + } + f.get("path").and_then(Value::as_str).map(str::to_owned).ok_or_else(|| ToolError::Output("models: no path".into())) +} + #[cfg(test)] mod tests { use super::*; @@ -133,4 +153,24 @@ mod tests { let s = Speech { exe: "Z:/does/not/exist/speech.exe", env: &env }; assert!(matches!(s.devices().await, Err(ToolError::Spawn(..)))); } + + fn catalog() -> Value { + serde_json::json!({"models": [{ + "name": "irodori-tts-large", "type": "q8_0", + "files": [ + {"type": "q8_0", "fetched": true, "path": "C:\\m\\large-q8.gguf"}, + {"type": "q4_k", "fetched": false, "path": "C:\\m\\large-q4.gguf"} + ] + }]}) + } + + #[test] + fn resolves_fetched_catalog_models_without_fetching() { + let c = catalog(); + assert_eq!(catalog_path(&c, "irodori-tts-large").unwrap(), r"C:\m\large-q8.gguf"); + assert_eq!(catalog_path(&c, "irodori-tts-large:q8_0").unwrap(), r"C:\m\large-q8.gguf"); + assert!(matches!(catalog_path(&c, "irodori-tts-large:q4_k"), Err(ToolError::NotFetched(_)))); + assert!(matches!(catalog_path(&c, "irodori-tts-large:f16"), Err(ToolError::Unknown(_)))); + assert!(matches!(catalog_path(&c, "nope"), Err(ToolError::Unknown(_)))); + } } diff --git a/src/app/Rail.tsx b/src/app/Rail.tsx index a2700bc..962ec83 100644 --- a/src/app/Rail.tsx +++ b/src/app/Rail.tsx @@ -94,6 +94,7 @@ export function engineAction( function EnginePanel({ close }: { close: () => void }) { const settings = useApp((s) => s.settings); const engine = useApp((s) => s.engine); + const starting = useApp((s) => s.engineStarting); const app = useApp.getState; const chosen = chosenProfile(settings); const action = engineAction(engine, chosen); @@ -110,7 +111,7 @@ function EnginePanel({ close }: { close: () => void }) { className={`menu-item${p.id === chosen?.id ? " chosen" : ""}`} role="menuitemradio" aria-checked={p.id === chosen?.id} - disabled={engine.state === "loading"} + disabled={engine.state === "loading" || !!starting} onClick={() => void app().saveSettings({ ...settings, activeProfileId: p.id })} > @@ -132,8 +133,8 @@ function EnginePanel({ close }: { close: () => void }) { )} {chosen && (action === "start" || action === "switch") && ( - )} {running && ( diff --git a/src/app/StatusBar.test.tsx b/src/app/StatusBar.test.tsx index 760dc31..d69f66e 100644 --- a/src/app/StatusBar.test.tsx +++ b/src/app/StatusBar.test.tsx @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { fireEvent, render, screen } from "@testing-library/react"; -import { StatusBar, formatEta } from "./StatusBar"; +import { StatusBar, downloadSummary, formatEta } from "./StatusBar"; import { useApp } from "../store/app"; -import type { AppSettings } from "../lib/types"; +import type { AppSettings, DownloadProgress } from "../lib/types"; const cancelAll = vi.fn(async () => {}); const settings: AppSettings = { @@ -51,6 +51,8 @@ describe("StatusBar", () => { jobDurations: [], runningSince: null, engine: { state: "ready", profileId: "p1", model: {}, sampleRate: 48000 }, + downloads: {}, + engineStarting: null, }); }); @@ -92,4 +94,39 @@ describe("StatusBar", () => { expect(screen.getByText(/エンジン停止中/)).toBeTruthy(); expect(screen.queryByRole("button", { name: /モデルを入手/ })).toBeNull(); }); + + it("shows a running download anywhere in the app and opens its dialog (D-59)", () => { + useApp.setState({ dialog: null, downloads: { [dl.id]: dl } }); + render(); + fireEvent.click(screen.getByRole("button", { name: /irodori-tts-large:q8_0 25%・残り 3分0秒/ })); + expect(useApp.getState().dialog).toBe("catalog"); + }); + + it("says the start is being prepared before the engine reports loading", () => { + useApp.setState({ engine: { state: "stopped" }, engineStarting: "p1" }); + render(); + expect(screen.getByText("Irodori Small の起動を準備中…")).toBeTruthy(); + }); +}); + +const dl: DownloadProgress = { + id: "irodori-tts-large:q8_0", + phase: "downloading", + file: "", + done: 1e9, + total: 4e9, + bytesPerSec: 1e7, + etaSecs: 180, + message: "", + profileId: null, +}; + +describe("downloadSummary", () => { + it("names the first running download and counts the rest; finished ones are left out", () => { + expect(downloadSummary({})).toBeNull(); + expect(downloadSummary({ a: { ...dl, phase: "done" } })).toBeNull(); + const two = { a: dl, b: { ...dl, id: "qwen3-asr-0.6b:q8_0", phase: "verifying" as const } }; + expect(downloadSummary(two)).toBe("irodori-tts-large:q8_0 25%・残り 3分0秒(ほか 1 件)"); + expect(downloadSummary({ b: two.b })).toBe("qwen3-asr-0.6b:q8_0 検証中"); + }); }); diff --git a/src/app/StatusBar.tsx b/src/app/StatusBar.tsx index 73db719..584afda 100644 --- a/src/app/StatusBar.tsx +++ b/src/app/StatusBar.tsx @@ -1,7 +1,23 @@ // The bottom bar: the generation queue on the left, the loaded model on the right. import { chosenProfile, queueEta, useApp } from "../store/app"; +import type { DownloadProgress } from "../lib/types"; +import { fmtEta } from "../lib/text"; import { Icon } from "./icons"; +const ACTIVE = ["checking", "downloading", "verifying"]; + +/** `irodori-tts-large:q8_0 42%・残り3分` for the first running download, and how many more run (D-59). */ +export function downloadSummary(downloads: Record): string | null { + const running = Object.values(downloads).filter((d) => ACTIVE.includes(d.phase)); + const d = running[0]; + if (!d) return null; + const pct = d.total ? `${Math.floor(Math.min(100, (d.done / d.total) * 100))}%` : ""; + const what = + d.phase === "downloading" ? [pct, `残り ${fmtEta(d.etaSecs)}`] : [d.phase === "verifying" ? "検証中" : "確認中"]; + const more = running.length > 1 ? `(ほか ${running.length - 1} 件)` : ""; + return `${d.id} ${what.filter(Boolean).join("・")}${more}`; +} + export function formatEta(sec: number): string { return sec < 60 ? `約${Math.ceil(sec)}秒` : `約${Math.floor(sec / 60)}分${Math.ceil(sec % 60)}秒`; } @@ -19,8 +35,21 @@ export function StatusBar() { s.engine.state === "stopped" || s.engine.state === "failed" ? chosenProfile(s.settings) : undefined, ); const needsModel = missing && !missing.model ? missing : null; + const starting = useApp((s) => s.engineStarting); + const startingName = profiles?.find((p) => p.id === starting)?.name ?? starting; + const download = useApp((s) => downloadSummary(s.downloads)); return (