diff --git a/AGENTS.md b/AGENTS.md index 3bf3f69..d92e521 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,7 +30,7 @@ VIRTUAL_ENV=.venv uv pip install -e '.[dev]' | contract | `SPEC.md`, `docs/spec/`, `AGENTS.md`, `Makefile`, `scripts/check.sh` | changing an acceptance assertion needs maintainer agreement | | pipeline | `src/subsmith/pipeline/`, `tests/pipeline/` | pure functions, no Qt imports | | onscreen | `src/subsmith/onscreen/`, `tests/onscreen/` | OCR adapters behind a protocol; models are fetched, never committed | -| languages | `src/subsmith/languages/profiles/*.toml` | data only; adding a language is a TOML file and needs no test edit | +| languages | `src/subsmith/languages/` | one TOML file per language under `profiles/`, named by its tag, plus the loader and registry; data only in the files | | worker | `src/subsmith/worker/` | process boundary, JSON-lines protocol | | ui | `src/subsmith/ui/` | Qt widgets only, no pipeline logic | | packaging | `packaging/`, `.github/workflows/`, `flake.nix` | release artifacts | @@ -56,4 +56,8 @@ VIRTUAL_ENV=.venv uv pip install -e '.[dev]' - A user-editable TOML names its JSON Schema with a `#:schema` directive on its first line, and CI validates it. TOML has no schema key of its own, so the directive is a comment that editors read and the loader ignores. +- A language profile is named by its canonical lowercase BCP 47 tag, and the tag is its + identity: filenames, settings keys and deliverables all use it. The only codes a profile + stores are the ones that differ from the tag, under `[codes]`: `whisper` for the model's + token and `aliases` for the spellings containers write. No ISO code is stored. - Never push to the default branch. Branch, push, open a PR, a human merges. diff --git a/SPEC.md b/SPEC.md index 3a14aa3..3d7f3a9 100644 --- a/SPEC.md +++ b/SPEC.md @@ -34,8 +34,8 @@ provider, and why the app must run without a Python installation. context field, a glossary block, and rules loaded from language profile files. 6. Shape cues to a per-target-language policy, fitting text by splitting, extending into silence, then condensing, and trimming only as a logged last resort. -7. Write an SRT and a styled ASS from one cue list, plus the artifacts: segments, - onscreen, glossary, translated text, QA report. +7. Write an SRT and a styled ASS from one cue list, with the QA report and the working + files kept inside the job directory rather than offered as outputs. 8. Read on-screen text with a local OCR engine, discard the fragments that match recognised speech, and treat the rest as content: translated, timed to the frame it appeared on, and placed above the dialogue. diff --git a/docs/spec/01-ingest.md b/docs/spec/01-ingest.md index 501cdb5..d58c4bc 100644 --- a/docs/spec/01-ingest.md +++ b/docs/spec/01-ingest.md @@ -25,6 +25,11 @@ more than a handful of cues. Image-based tracks (PGS, VobSub) are not a text sou are listed, marked unusable, and their presence tells lane 10 where on the picture the caption band sits. +A track's language string is compared against the requested source through the language +registry's alias map (lane 11), never by string equality: containers write ISO 639-2 +(`kor`, `chi`, `zho`), and BCP 47 does not contain those strings when a two letter form +exists. + Audio extraction is `ffmpeg -vn -ac 1 -ar 16000`. No trimming, no loudnorm, no VAD. Any pre-ASR silence removal destroys the mapping back to the original timeline. diff --git a/docs/spec/05-fit-and-timing.md b/docs/spec/05-fit-and-timing.md index aa8fac0..c531374 100644 --- a/docs/spec/05-fit-and-timing.md +++ b/docs/spec/05-fit-and-timing.md @@ -4,7 +4,8 @@ Make each cue readable, inside its time, without losing content. ## Inputs -`segments.json` word times, `translated.json`, the target language profile's cue policy. +`segments.json` word times, `translated.json`, and the cue policy the in-memory settings +object resolves for the target language. ## Outputs @@ -13,8 +14,14 @@ adjustments that were made. ## Design notes -Cue policy per target language: characters per line, maximum lines, maximum characters -per second, minimum duration, maximum duration. English defaults 42, 2, 21, 0.8 s, 7 s. +Cue policy per target language: characters per line, characters per second, minimum +duration, maximum duration. The shipped defaults live in `_defaults.toml` and a profile +overrides any of them; English's are 42, 21, 0.8 s, 7 s. The effective numbers enter the +in-memory settings object at load, and this stage reads them from there rather than from +the profile or a constant, so a settings screen is additive. v1 ships no screen for them; +that absence is the only limit on editing. Line counts are not part of the policy: how +many lines a subtitle may occupy is a screen rule (FT5.9), not a property of a language, +and the policy comes from the target because it describes how the output language reads. **Screen budget.** The unit that must not be exceeded is the frame, not the cue: at most three text lines at any instant. Dialogue takes one or two of them, on-screen graphics @@ -50,8 +57,8 @@ offset; the offset is applied only at write time. ## Acceptance assertions - FT5.1 After shaping, no two cues overlap and every cue has `end_ms > start_ms`. -- FT5.2 Every cue has at most the profile's lines and characters per line, or carries a - logged trim. +- FT5.2 Every cue has at most two dialogue lines and the target's characters per line, or + carries a logged trim. - FT5.3 A merge's start equals the earliest contained word start and its end equals the latest contained word end. - FT5.4 For every unsplit, unmerged cue, `abs(cue.start_ms - first_word.start_ms)` and @@ -62,7 +69,7 @@ offset; the offset is applied only at write time. candidate is used. - FT5.7 A non-zero display offset shifts every cue by that amount at write time only, and re-reading stored cues shows the unshifted values. -- FT5.8 Cues shorter than the profile minimum are merged into a neighbour or reported in +- FT5.8 Cues shorter than the target minimum are merged into a neighbour or reported in the QA summary, never silently dropped. - FT5.9 No cue carries more than three text lines. A cue with two dialogue lines has at most one graphics line, a cue with one dialogue line has at most two, and graphics lines @@ -70,4 +77,6 @@ offset; the offset is applied only at write time. - FT5.10 A cue that holds two speakers has one speaker per line, and each line after the first begins with `ยป` and a space, counted inside the line's character budget. - FT5.11 In every cue, graphics lines precede dialogue lines. +- FT5.12 The fit stage reads its four numbers from the in-memory settings object; changing + the target's cue policy there changes the result without touching the stage. diff --git a/docs/spec/06-output.md b/docs/spec/06-output.md index 17b8558..2dc080f 100644 --- a/docs/spec/06-output.md +++ b/docs/spec/06-output.md @@ -8,8 +8,13 @@ The final cue list, the job directory, the display offset. ## Outputs -`..srt`, `..ass`, `qa.json`, and the retained artifacts: -`segments.json`, `onscreen.json`, `glossary.tsv`, `translated.json`. +The deliverables are `..srt` and `..ass`. The job directory also +holds `qa.json` for the UI's QA report and the working files each stage needs: +`segments.json`, `onscreen.json`, `glossary.tsv`, `translated.json`, `cues.json`. A +working file is internal state for resume and the cue table, never a deliverable: v1 has +no flag that exposes one, and a debug dump is out of scope. The tag is the target +profile's canonical BCP 47 tag, lowercased, so two scripts of one language cannot collide +in a folder. ## Design notes @@ -30,16 +35,24 @@ Placement follows the cue policy: graphics above dialogue, both bottom anchored with the alignment field left to the profile so a player that anchors at the top keeps graphics above dialogue. -**Both.** Writes are atomic: write to a temporary name in the same directory, then rename. +**Writes are atomic.** Write to a temporary name in the same directory, then rename. An existing output file is never overwritten without an explicit overwrite flag, in which case the previous file is renamed with a `.bak` suffix first. The display offset is applied to both files at write time. +**Output format is a setting, both by default.** The in-memory settings object carries +the format choice: `both` (the v1 default), `srt`, or `ass`. v1 renders no control for it, +on the same rule as the cue numbers; the writer reads the value at job start, so adding +the screen later does not change the writer. `ass` alone is the lossless choice, `both` +adds the portable copy, and `srt` alone flattens graphics into ordered plain lines. A +format that cannot carry styling still writes the text; it never drops a graphics line +silently. + `qa.json` carries: cue count, covered duration, average characters per second, longest line, overlap count, maximum cue-to-word delta, count of trims, count of condenses, glossary audit warnings, first speech onset versus first cue start, the device and model -used, the OCR engine and its execution provider, the number of on-screen cards, and the -number of attribution cards left untranslated. +used, the OCR engine and its execution provider, the number of on-screen cards, the number +of attribution cards left untranslated, and the resolved source and target tags. ## Acceptance assertions @@ -50,11 +63,14 @@ number of attribution cards left untranslated. - OUT6.3 A file that already exists is not overwritten unless the overwrite flag is set, and then the old file is preserved as `.bak`. - OUT6.4 `qa.json` contains every field listed above and validates against the schema. -- OUT6.5 `segments.json`, `onscreen.json`, `glossary.tsv`, and `translated.json` remain in - the job directory after a successful run. +- OUT6.5 A successful run exposes only the subtitle deliverables and the QA report: the + writer returns the SRT and ASS paths (or the one the format selects), and no working + file is presented as an output. - OUT6.6 Hours beyond 99 do not break the SRT time format, verified with a synthetic cue at 100 hours. -- OUT6.7 The output filename uses the source stem and the target language code. +- OUT6.7 The output filename uses the source stem and the target profile's tag, + lowercased, and the cost of a hyphenated suffix (player language selection is by two or + three letter code) is stated in the release notes or the UI, not implied. - OUT6.8 A cue carrying both kinds writes its graphics lines before its dialogue lines in both files, and no block exceeds three lines. - OUT6.9 A generated ASS declares both styles, and a mixed event carries the inline @@ -63,3 +79,6 @@ number of attribution cards left untranslated. `Dialogue` and `ScreenText`, and events whose start is before their end. - OUT6.11 The same cue list and offset produce an SRT and an ASS whose event times agree to the millisecond. +- OUT6.12 The writer selects its files from the settings object's format: `both` writes + the pair, `ass` writes only ASS, `srt` writes only SRT, and with no value set the + default is `both`. diff --git a/docs/spec/08-ui.md b/docs/spec/08-ui.md index 5a6e8fa..36ffaa0 100644 --- a/docs/spec/08-ui.md +++ b/docs/spec/08-ui.md @@ -43,6 +43,14 @@ when the engine is `llm`, an `[onscreen.llm]` table of `base_url`, `model` and ` base URL may be absent, because nothing needs it until a job runs, and the check that starts a job names the field it needs. +Language prompt overrides live in the same settings file, keyed by tag and folded the +same way as a profile filename: `[language."ko".prompt]` with `source_rules` or +`target_rules`. They are the one language setting a person types by hand; the screen does +not render them. The target's cue numbers and the output format are settings too, carried +by the same in-memory object, seeded from the shipped profile and from `both`; v1 renders +no control for either. A `cue` key under `[prompt]` is refused because that table holds +prompt fragments only. + Any of the six connection strings, three under `[translate]` and three under `[onscreen.llm]`, may be written as `{env:NAME}` or `{file:PATH}` instead of a literal. A reference is resolved once at load and only when it is the whole value, so nothing is @@ -51,9 +59,9 @@ trailing newline removed; and an unset variable or an unreadable file refuses th naming the variable or the path. The file keeps the reference when the screen saves, so a machine-managed configuration survives a save untouched. -There is no hand author for this file, so it carries no JSON Schema and no `#:schema` -directive; the screen and the loader enforce what it accepts, and the assertions below pin -the messages. +The screen and the loader are the authors, except for `[language."".prompt]`, which +a person types by hand. The file therefore carries no JSON Schema and no `#:schema` +directive; the loader enforces what it accepts, and the assertions below pin the messages. The display offset is applied by the write stage, so dragging it after a run rewrites the SRT without touching the artifacts. @@ -84,8 +92,9 @@ is a layout change, not a rewrite. naming that field, not a crash. - UI8.12 Saving a base URL without an `http` or `https` scheme is refused with the field named. -- UI8.13 A `cue` key under `[language.""]` is refused with the key named, because cue - numbers are not user-configurable in v1. +- UI8.13 A `cue` key under `[language."".prompt]` is refused with the key named, + because that table holds prompt fragments only; cue numbers are read from the settings + object, not rejected. - UI8.14 A language key that is not a BCP 47 tag is refused, naming the key. - UI8.15 A `{env:NAME}` or `{file:PATH}` reference is resolved at load and is still the reference in the file after the screen saves. @@ -93,3 +102,8 @@ is a layout change, not a rewrite. load, naming the variable or the path, rather than sending an empty key. - UI8.17 A `{env:...}` or `{file:...}` sequence that is not the whole value is left as text, so a prompt fragment or a path containing braces reaches the endpoint unchanged. +- UI8.18 A language prompt override keyed by tag replaces that language's fragment for + the next job. +- UI8.19 The cue numbers and output format the job uses come from the in-memory settings + object, seeded by the target profile and by `both` respectively, even though v1 renders + no control for either. diff --git a/docs/spec/11-languages.md b/docs/spec/11-languages.md new file mode 100644 index 0000000..61c309c --- /dev/null +++ b/docs/spec/11-languages.md @@ -0,0 +1,88 @@ +# Lane 11: languages + +Identity, codes and defaults for the language profiles. + +## Inputs + +One TOML file per language under `src/subsmith/languages/`, the shared `_defaults.toml` +beside them, and the user's settings file. + +## Outputs + +A registry of loaded profiles, the map from container language strings to tags, and the +resolved source-target pair a job runs with. + +## Design notes + +**The file name is the identity.** A profile is named by its canonical BCP 47 tag, in +lowercase: `en.toml`, `ko.toml`, `zh-hant.toml`. Tags are case-insensitive (RFC 5646 +section 2.1.1), so lookups fold case and the on-disk name is lowercase because Windows +and macOS cannot hold two files that differ only in case. A tag the registry has +deprecated is refused with the replacement in the message (`jw` is `jv`, `zh-yue` is +`yue`), so the fix is in the error rather than in a comment. The file does not repeat its +tag: a `tag` key is refused. + +**Three vocabularies, one of them stored.** The tag names the language and everything the +app writes. The ISO code is the tag's language subtag, derived and never stored: two +letters is ISO 639-1, three is ISO 639-2 or 639-3, and the IANA registry says which. The +Whisper token is the only code a profile may carry, because faster-whisper accepts a +fixed set of 100 tokens and is not a BCP 47 consumer: `jv.toml` carries +`[codes] whisper = "jw"`, and every other language inherits its subtag. + +**Container strings are aliases.** Matroska's `Language` element and MP4's `mdhd` field +are ISO 639-2, and BCP 47 mostly does not contain those strings at all: the registry has +`ko`, `zh`, `jv`, and not `kor`, `zho`, `chi`, `jav`. Each profile therefore lists the +spellings other software uses in `[codes] aliases` (`ko.toml` carries `kor`), and the +registry builds the map once at startup. Aliases are inbound only. A string claimed by +two languages is ambiguous by construction, which is honest, because `chi` can be +Mandarin or Cantonese; a test pins the intended set so an accidental duplicate fails the +gate. Matching a track to a profile prefers the requested tag and reports the ambiguity +in `qa.json`; a string with no claim matches nothing, and recognition runs. + +**Cue numbers are settings with shipped seeds.** `_defaults.toml` carries characters per +line, characters per second, minimum duration and maximum duration. A profile overrides +any of them in its own `[cue]` table, and usually overrides none. At load the target +profile's four numbers enter the same in-memory settings object every other setting comes +from, and the fit stage reads them there, never from a module constant or directly from +the profile. v1 ships no screen for them, and that is the whole of the limitation: the +value already lives where a screen would write it. Line counts are not here: how many +lines a subtitle may occupy is a screen rule (FT5.9), so `max_lines` in a cue table is +refused. The policy is the target's, because it describes how the output language reads; +a source profile's numbers are ignored until that language is a target. + +**Prompt fragments are the one language setting with a screen in v1.** A user may +replace a language's prompt fragments under `[language."ko".prompt]`, keyed by tag and +resolved the same way as a filename. A `cue` key under `prompt` is refused because that +table holds prompt fragments only, not because cue numbers are fixed; the numbers belong +at the language level and reach the pipeline through settings. Pair-keyed settings do not +exist: adding a target language must not multiply configuration. + +**Deliverables carry the tag.** The output is `..srt` and `..ass`, +lowercase, so `zh-hant` and `zh-hans` cannot collide. The cost is stated: VLC and mpv +select subtitle tracks by two or three letter codes, so a hyphenated suffix displays but +is not guaranteed to match a language preference. The prompt names each language as +`Name [tag]`, because the model reads the name and the tag disambiguates the script. + +## Acceptance assertions + +- LG11.1 Every shipped profile is named by a canonical lowercase BCP 47 tag, and loading + one by any casing resolves to the same profile. +- LG11.2 A profile file that carries a `tag` key is refused, and the message names the + filename as the identity. +- LG11.3 A deprecated tag is refused with its preferred replacement in the message. +- LG11.4 No profile stores an ISO code; the language subtag is the only ISO code the + loader derives. +- LG11.5 `codes.whisper` is refused unless it is one of the tokens faster-whisper + accepts, and it defaults to the language subtag when absent. +- LG11.6 Every alias claimed by a profile resolves through the registry to that profile, + and a string claimed by two languages is reported as ambiguous rather than resolved. +- LG11.7 Cue numbers reach the fit stage from the in-memory settings object, seeded by + `_defaults.toml` and the target profile, and a line count inside a cue table is + refused. +- LG11.8 The cue policy a job uses is the target language's. +- LG11.9 The deliverable is `..srt` and `..ass` with the tag + lowercased. +- LG11.10 The prompt names each language as `Name [tag]`. +- LG11.11 Settings overrides are keyed by tag and accept either prompt fragment in v1; + no pair-keyed setting exists, and cue numbers are resolved in the same in-memory + settings object rather than held as constants. diff --git a/docs/superpowers/specs/2026-12-03-subsmith-design.md b/docs/superpowers/specs/2026-12-03-subsmith-design.md index 87e0235..4fdeea1 100644 --- a/docs/superpowers/specs/2026-12-03-subsmith-design.md +++ b/docs/superpowers/specs/2026-12-03-subsmith-design.md @@ -12,7 +12,8 @@ nobody does. subsmith is that pipeline as a desktop application. A user picks a video, picks a source and a target language, optionally describes what the video is, presses start, and gets an -SRT they can watch with plus the artifacts to revise it. Speech recognition runs locally. +SRT and a styled ASS they can watch with; the working files stay in the job directory +rather than being offered as outputs. Speech recognition runs locally. Translation is a request to whichever OpenAI-compatible endpoint they configure. The design is shaped by two failures an earlier run of the same pipeline produced, and @@ -156,10 +157,14 @@ Job directory, one per job, named by timestamp and source stem: glossary.tsv hidden working file translated.json id to text, chunk and attempt cues.json final cues plus adjustment log - qa.json metrics and warnings - title.en.srt the deliverable + qa.json metrics and warnings, shown in the UI + title.en.srt deliverable + title.en.ass deliverable ``` +The two subtitle files are the deliverables. Every other file is job state that resume and +the cue table read; none is offered as an output. + ## Decisions ### Timing: four places it can drift