Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <model>` 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 <model>` 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`.

Expand Down
50 changes: 50 additions & 0 deletions assets/models/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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(参照音声の自動書き起こし)",
Expand Down
17 changes: 16 additions & 1 deletion docs/deviations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion docs/engine-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
26 changes: 20 additions & 6 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,21 @@ pub struct CatalogView {
pub running: Vec<String>,
}

/// 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<CatalogView> {
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();
Expand Down Expand Up @@ -583,17 +594,17 @@ 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,
variant_id: String,
dest_dir: String,
license_accepted: bool,
) -> R<String> {
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));
Expand Down Expand Up @@ -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
}
}
}
};
Expand Down
69 changes: 69 additions & 0 deletions src-tauri/src/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub struct Variant {
pub unsupported_reason: String,
pub vram_bytes: u64,
pub files: Vec<CatalogFile>,
/// Already in speech.cpp's model folder (`speechPull` models only; filled in by [`Catalog::merge_speech`]).
#[serde(default)]
pub fetched: bool,
}

fn yes() -> bool {
Expand Down Expand Up @@ -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<Variant> = 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)?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
Loading