diff --git a/CLAUDE.md b/CLAUDE.md index 78e29c8..c0a09f8 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`, `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. +**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; 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`. @@ -68,9 +68,11 @@ VS_SPEECH_EXE=.engine/speech.exe VS_DRAMA_MODEL=path/to/Drama-35B-A3B-Japanese-v - The voice library (`.voice.gguf` files) lives in the app data dir under `voices/`. - Scratch audio lives in `work//` in the local app data dir, one per running instance and locked by its `.lock` (`work.rs`, D-39): untitled projects' takes, `design/` candidates and `trimmed/` references. At start, folders that no running instance holds are swept. -**Debug handles.** For E2E driven over DevTools, `window.__speechorus` exposes the stores and actions (D-19), and the window event `vs-add-refs` adds reference audio by path (D-35). +**Debug handles.** For E2E driven over DevTools, `window.__speechorus` exposes the stores and actions (D-19), and the window event `vs-add-refs` adds reference audio by path (D-19). ## Project process -- `docs/architecture.md` is the approved plan. Every departure from it is recorded in `docs/deviations.md` as a `D-NN` entry (what / why / workaround / user impact, plus a status tag). Confirm large changes that affect a requirement with the user before making them, and add a D-entry for any deviation. Commit messages refer to these IDs (e.g. "(D-37)"). +- `docs/architecture.md` describes the design as it is now; update it when the structure changes. Known gaps, deferred features and planned work are GitHub Issues (`gh issue list`): check the open ones for the area before starting, close them from the PR (`Fixes #N`), and open one for a gap you find but do not fix. +- `docs/decisions/` holds the decision records (`D-NN-slug.md`, indexed in its `README.md`): workarounds for engine or library limits, approaches chosen over others (with the rejected ones and why), behavior that is on purpose although it looks wrong, and rules later work must keep. Read the records for the area before changing it, so a constraint or a rejected approach is not undone by accident. Write a new record (next free ID) only for such a decision, not for a plain feature or fix; when a decision changes, update the old record's status instead of leaving two that disagree. Code comments and commit messages cite the IDs (e.g. "(D-37)"). +- Development is left to Claude. Decide technical and design matters yourself; ask the user first only before removing a feature or substantially changing how the app behaves for them, touching their data or settings outside the repository, or doing anything hard to undo or outward-facing. - Known engine limitation: a single-request `<|speaker:N|>` scene with Drama-3-Japanese voices only speaker 0, so per-line scene mode is the default (D-01). diff --git a/README.md b/README.md index 91c65e2..d4e928a 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ npx tauri build --no-bundle CI (`.github/workflows/ci.yml`) runs the same checks on every pull request into `main` and every push to `main`. Run `npm run check` before you push anyway. The pre-commit hook formats and lints only the staged files (Oxlint `--fix`, Oxfmt, rustfmt); skip it with `git commit --no-verify` when you need to. -Dependencies are held to versions published at least 7 days ago, and install scripts run only for packages approved in `package.json` `allowScripts` (`.npmrc`; needs npm 11.19+). Crates in `Cargo.lock` are checked the same way by `scripts/cargo-release-age.mjs`. See D-43 in `docs/deviations.md`. +Dependencies are held to versions published at least 7 days ago, and install scripts run only for packages approved in `package.json` `allowScripts` (`.npmrc`; needs npm 11.19+). Crates in `Cargo.lock` are checked the same way by `scripts/cargo-release-age.mjs`. See [D-43](docs/decisions/D-43-supply-chain.md). `speech.exe` is looked up in this order: the `SPEECHORUS_SPEECH` environment variable, next to the executable (`speech/speech.exe`, `speech.exe`), then `.engine/speech.exe` (for development). @@ -76,7 +76,9 @@ VS_SPEECH_EXE=.engine/speech.exe VS_DRAMA_MODEL=path/to/Drama-35B-A3B-Japanese-v ## Documentation -- [docs/architecture.md](docs/architecture.md): design (the approved plan) +- [docs/architecture.md](docs/architecture.md): how the app is built +- [docs/decisions/](docs/decisions/README.md): decision records (why things are the way they are, and what was tried and rejected) +- [Issues](https://github.com/eddybean/speechorus/issues): known gaps, deferred features and planned work - [docs/engine-protocol.md](docs/engine-protocol.md): speech.cpp worker protocol and measurements (memory, time, known limitations) ## License diff --git a/docs/architecture.md b/docs/architecture.md index c8a0820..ac713ed 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,155 +1,107 @@ -# Speechorus: a GUI for speech.cpp (Drama-3-Japanese first, Irodori-TTS second) - -## Context -The goal is an easy-to-use Japanese TTS app built mainly around Drama-3-Japanese (`StudioYebisu-ship-it/Drama-3-Japanese-speech-cpp-gguf`). Model switching (Irodori-TTS and others) is part of the design from the start. The repository started empty, so this is a new build. This plan covers research and design only; **implementation and testing were done afterwards in separate sessions.** - -### Research findings (the basis for the decisions) -- **TTS engine: use the existing speech.cpp as is** (https://github.com/nyosegawa/speech.cpp, MIT, v0.11.2+) - - It is a single executable `speech` that runs from the CLI. That meets the requirement for a standalone, CLI-runnable TTS engine. We add no CLI of our own (user decision). - - Synthesis models it supports: `drama-3`, `irodori-tts` / `irodori-tts-mf` / `irodori-tts-large`, `qwen3-tts-*`. It also has ASR (`qwen3-asr-0.6b`, `reazonspeech-v2`, and others). - - Subcommands: `tts`, `voice` (builds a voice file from reference audio), `serve` (OpenAI-compatible HTTP), `worker` (JSON Lines over stdin/stdout, model stays loaded), `asr`, `info --json`, `devices --json`, `models --json`, `pull`. - - The Windows release is a Vulkan build only. With 24 GB or more of NVIDIA VRAM, the Japanese Q4_K/Q5_K runs on the official Vulkan binary (`GGML_VK_DISABLE_F16/COOPMAT/COOPMAT2=1` required; **CUDA is not allowed for Q4_K/Q5_K**). The `.gguf.json` sidecar must sit next to the model. -- **Existing freeware** - - Mixomo/Fish_Drama_3_Easy_GUI (Gradio, Windows only, 1 commit): the model list is fixed and does not include the Japanese GGUF. It has no tag-insertion UI, no project saving and no per-line settings. **It does not meet the requirements.** - - The `speech serve --open` web page and the official Irodori Gradio page are both minimal. **The decision is to build only the GUI ourselves.** -- **Drama-3 features (what the GUI must expose)** - - Acting tags: `[驚いて]本当に?[明るく]…`. A tag takes effect from the point where it is written. TAG_LIST.md has about 130 general tags plus an NSFW category. - - Free-text voice design: a description at the start of the text, e.g. `[落ち着いた25歳の女性。…]`, used with `voice=none`. - - Multiple speakers: `<|speaker:0..15|>` covers a whole scene in one request. Several references can be combined into a single cast voice with `speech voice … --speaker N`. - - Reference audio: `speech voice drama-3 ref.wav --transcript "…" out.voice.gguf` (a transcript is required). - - Options: `seed`, `temperature` (1), `top_k` (30), `top_p` (0.9), `max_seconds` (47.6, max 95.1), `experts_on_cpu`. **It has no speed, pitch or `instructions` options** (sending them returns 400). - - Output is WAV (44.1 kHz, check `X-Sample-Rate`). Long text is split automatically into chunks of about 300 bytes, up to 8192 tokens. -- **Irodori-TTS**: `instructions` (VoiceDesign caption), `speed`, `steps`, `seconds`, `duration_scale`, cfg_*, 56 emoji tags. A reference WAV can be used directly with no transcript. Output is 48 kHz, up to 30 s per request. -- **Feature inventory (AivisSpeech/VOICEVOX)**: multi-line editor, per-line speaker, txt import (`キャラ,テキスト` format), per-line playback, play all, export each line as a WAV (filename template, serial numbers), .txt/.lab, project save, Undo/Redo, presets, drag to reorder, keyboard shortcuts, auto-split on paste, memo syntax. Accent and intonation editing **cannot be offered for an LLM-type model**, so it is out of scope. - -### User decisions -- GPU: NVIDIA 24 GB or more, so the main configuration is Q4_K on Vulkan with the official binary. IQ3_XXS (patched CUDA build) is a "custom binary path" option only. -- GUI: Tauri 2 + React + TypeScript. -- CLI: speech.cpp only (no CLI of our own). -- v1 scope: script editor with batch generation, take management, automatic transcription of reference audio, Irodori-TTS support. - -## Architecture +# Speechorus architecture -``` -┌───────────── Tauri app (speechorus) ─────────────┐ -│ React UI (WebView2) │ -│ ScriptEditor / TagPalette / VoiceLibrary / │ -│ TakePanel / ModelManager / ExportDialog │ -│ │ invoke / events │ -│ Rust core │ -│ engine:: EngineSupervisor (child process, │ -│ lifecycle, model switching) │ -│ models:: ModelAdapter trait │ -│ ├ Drama3Adapter │ -│ └ IrodoriAdapter │ -│ jobs:: GenerationQueue (sequential, cancel, │ -│ progress) │ -│ project:: .vsproj (JSON) + takes/ folder │ -│ audio:: WAV concat/silence/SRT/.txt export │ -│ (hound) │ -└────────┬──────────────────────────────────────────┘ - │ spawn (one resident process) - speech worker --device Vulkan0 … ← model stays loaded - speech voice … / speech asr … ← short-lived processes -``` +How Speechorus is built today. Keep this file current when the structure changes; the reasons behind the choices are +in [decisions/](decisions/README.md) (start with [D-00](decisions/D-00-speech-cpp-gui.md)), and known gaps and planned +work in [GitHub Issues](https://github.com/eddybean/speechorus/issues). The engine protocol and its measurements are in [engine-protocol.md](engine-protocol.md). + +## Goal and scope + +A Windows desktop studio for Japanese TTS, built around Drama-3-Japanese, with Irodori-TTS as the second model and +room for more. It is a GUI over [speech.cpp](https://github.com/nyosegawa/speech.cpp) (`speech.exe`, v0.11.2+, Vulkan +build); the app has no engine or CLI of its own and ships no model files. + +What it does: + +- **Script editor**: lines with a cast, text, per-line option overrides, silences and a memo; multi-select, drag, + copy/paste of lines, auto-split on paste, txt/csv import (`キャラ,テキスト`), Undo/Redo. +- **Acting tags**: a searchable palette per model (Drama-3 brackets, Irodori emoji; NSFW hidden by default), + highlighting in a CodeMirror line editor, recent tags, a voice-design prompt per cast. +- **Voices**: an app-wide library of `.voice.gguf` files made with `speech voice` from trimmed references with ASR + transcripts, prompt-only voices, voice design from candidates, multi-speaker cast voices. +- **Generation**: a sequential queue (one line, selection, all, or only lines without takes), N takes per line, seeds + random / fixed / incrementing / pasted, cancel, ETA. Scenes per line or in one request (D-01). +- **Takes**: play, star, select, delete, copy the seed; continuous playback with silences. +- **Export**: each line as WAV (file-name template), a combined WAV, SRT and .txt. +- **Models**: profiles (adapter, model, speech.exe, device, env), the download catalog, the speech.cpp download, a + free-memory check before starting. + +Out of scope: accent and pitch editing (not possible with LLM-type models), and for now mp3/ogg and recording +(issues #47, #46). + +## Structure -### Key design points -1. **Model switching (ModelAdapter trait, Rust)** - - Each model declares the following: - - `capabilities()`: tag syntax (brackets or emoji), whether it supports instructions, speed, multiple speakers, whether reference audio needs a transcript, sample rate. - - `option_schema()`: name, type, default, range. - - `build_request(line, voice, options)` turns one line into the JSON sent to speech.cpp. - - `prepare_voice(ref_wavs, transcripts)` builds the `speech voice` arguments. - - The UI generates its settings panel dynamically from `option_schema`. The base schema can come from `speech info --json`; the adapter supplies UI hints (labels, slider ranges). - - The tag palette data is defined per model (`assets/tags/drama3.json`, `irodori-emoji.json`). - - Adding a model that is not on speech.cpp later means adding an `EngineBackend` trait (with `SpeechCppBackend` as its first implementation). In v1 only the trait boundary exists. -2. **Talking to the engine: `speech worker` (JSON Lines), with `serve` as the fallback** - - Reason: `serve` registers voices only at startup. Adding a voice would mean reloading a 20 GB model. The worker has messages such as `add_voice`. - - **First task for implementation:** read `docs/worker.md` (it could not be fetched during planning) and confirm the request/response fields, `add_voice`, progress and cancel. If they are missing, use `serve` and restart it with `--add-voice` whenever a voice is added. - - Only one engine process at a time. Switching models means stopping the current one, then starting the next. The UI shows the loading state. - - Show the VRAM requirement and free VRAM up front (`speech devices --json`). -3. **Keep memory low** - - The GUI stays at about 100–200 MB (Tauri/WebView2). - - The GUI loads no audio decoding or model of its own. - - Playback goes through an HTML `