Skip to content

Subtitle sync: judged by what was spoken

Subtitle timing used to be one number per media (media.sub_offset_s, nudged by hand on the sync screen). Measured on live media that model cannot express what is actually wrong: Bleach S17E48’s jimaku track drifts progressively (+9.9 s at the cold open → +18.1 s by the end), so the hand-set +17.2 s fixes the back half and leaves the front ~7 s out.

The first automatic answer (#144) was a scored ladder: alass against the rip’s embedded English track, else ElevenLabs forced alignment (both now removed), each run graded by a silero VAD metric and kept only when the score improved. It was retired (#289 §2, #307 §8) because the metric measured presence — the VAD hears that somebody is speaking, never that they are speaking this line. A timeline off by a whole cue still read covered ≈ 0.80; fictional-language audio satisfied it completely; a music video read as one continuous silence and could not be judged at all. The runner, the English-reference extraction and cleaning, the metric, its accept margin and flag threshold, the sync.mode ladder and the Pi’s cargo-built alass binary are gone. What replaced them judges every candidate timeline against what was actually said, and corrects it with offsets derived from that evidence. The .align.json timelines the old runner left beside a media’s subtitle files stay candidates forever: they won E47 and E48, and retiring the tool does not retire the answer.

Evidence (evidence.py, #289). collect() probes 8–12 windows of ~8 s (the sync.probe_windows cap), MDX-separated and transcribed blind — never forced alignment, which assumes the text it is supposed to prove. Unusable reads are rejected in code (filter_reads). Text anchors between read and cue give a constant_offset or, when the deltas refuse to agree, a per-cue anchored_retime. The whole pass — windows, reads with their hygiene rejections, anchors, every candidate and the lines it shows in each window — is stored on sync_run.evidence_json as a replayable case file.

The candidates are the live timeline, every subtitle file on disk (jimaku downloads, uploads, extracted embedded tracks and the #294 pool), each of those at the offset the evidence derives for it, and every stored .align.json. Every candidate reaches the judge through the same load-time filter (see below), derived from its raw cues.

Judgement (judge.py, #307). Two calls to the chosen judge (Jev or the local judge, through judge_service), everything else arithmetic:

  • Call A, one choice per window: spoken_dialogue / sung_lyrics / not_japanese. Sung and non-Japanese windows are excluded as input. The lines shown to this call come only from non-ASR candidates — an ASR-derived track “subtitles” the song too.
  • Call B, one noul per (candidate, usable window): is the heard speech among what this timeline shows here? Matched by sound, so 尸魂界 = ソウルソサイティ and a mangled name still counts.

Both calls are packed into requests under the judge’s MAX_REQUEST_BYTES (jev.py 48 000, local_judge.py 12 000), each request carrying only its own rows (#343, #351).

The score primitive is banned: it compresses and hedges (E48 answered 1.66 for a timeline right in 10 windows of 11), and the aggregation is code anyway.

The wire is the published TypeSafe contract (POST /v1/systemone, https://api.typesafe.ai/openapi.json), not a vocabulary of ours: a question carries instructions and, for a choice, criteria (choice name → when it applies); an answer carries its value under the name of its own type — {"type": "noul", "noul": 0.98}, {"type": "choice", "choice": …, "confidence": …, "probabilities": …}. #313: the first cut sent question/options and read answer/value, so every real call would have been a 422 and every schema-shaped answer a jev_bad_answer — and a mocked test agreeing with the client proved only that the client agreed with itself. The schema is vendored at core/tests/fixtures/typesafe_openapi.json and every request built and every canned answer used in test_jev_client.py is validated against it. One opt-in case (AUTOMINER_JEV_LIVE=1, a real key, a real billable call) makes the single round trip that checks the service agrees too.

decide() is pure and deterministic. Its gates, and the incident each one exists for:

gate value incident
usable windows ≥ 3 one hallucinated read at N=3 moved a correct timeline 3.91 → 2.37
lead over the best rival timeline under 2 windows, counted from sure answers only (#345, #352), the close call is settled on the full transcript (escalation below); a rival showing the same lines in every window is not one E4 applied on a lead of one; borderline nouls flip run to run
share of usable windows matched ≥ 60% a third of the episode is the stock lines, not the timeline

The highest-ranked candidate wins. Ties go current > least change, with one veto in front: a candidate transcribed by the same engine as the probes shares whisper’s errors and can never win a tie — except YouTube’s auto-captions, which are cross-engine and therefore real corroboration.

Escalation is mandatory before an apply whose lead sits at the boundary, whose offsets disagree piecewise, or whose coverage has head/tail gaps: the same sync.evidence job in full mode transcribes the whole episode and the verdict is remade on the dense evidence. Until it comes back the media is flagged. E4 is the incident this rule exists for.

Six verdicts, and two of them are refusals rather than decisions: apply (適用), leave_alone (現状維持), flag (要確認), thin_evidence (証拠不足), service_missing (サービス未設定) and no_candidates (候補なし, which materialises the blind transcript as a permanently flagged generated track). No path from a failure reaches “apply”: a judge that could not be reached has not approved anything, and a missing prerequisite is a stored, named flag rather than a silent skip.

thin_evidence is a claim about the EPISODE — we listened and there was not enough to go on — so a sweep whose every window was refused by the transcriber does not get to make it (issue #314). Those land as flag with the bundle’s own reason: probe_unreachable (the service is configured and not answering) or probe_failed (it answered and the answer was unusable), ahead of the candidate check so a media with no candidate and a dead probe can never materialise a blind transcript of audio nobody transcribed. The rejected windows are rows in the card’s evidence expander, each with its reason and the service’s own words, and the expander opens itself when a sweep kept nothing.

An outage is not thin evidence either (Wistoria E2, 2026-10-11: 8 of 12 windows probe_unreachable, decided on the other 4 as thin_lead, the source left on an offset fansub and never judged again). A window the recognizer service could not hear — no connection, or a refusal it lifts by itself (quota, 429, 502/503/504: the read’s transient) — is asked again within the pass, after 5 s and again after 30 s (evidence.RETRY_WAITS_S); nothing failed is cached, so a retry costs only the windows that were lost. A window heard while the separator was down (unreachable, failing, not installed) was heard from the mixture and paid for: it is kept and served until the separator answers, then read once more, separated (reads._owes_separation) — a separator outage no longer costs every window’s read again on every pass. A service that heard no window at all, or a round that won none back, is down rather than blipping (and a hung one costs a read timeout per window per round), so the retrying is left to the next pass. Windows still lost make the pass an outage (evidence.outage_reason) when the heard windows alone cannot conclude (judge.UNCONCLUDED: thin_evidence, thin_lead, current_within_lead — after the veto has been asked): decide refuses it as flag with probe_unreachable / probe_failed (the verdict keeps what it would have been under unconcluded) and records no verdict about the episode. A decision that clears its gates on the heard windows stands exactly as it would without the outage: every gate is counted on the windows that were heard, as for a short episode, and the outage rule only ever turns an unconcluded result into a refusal, never anything into an apply (the 2026-10-11 replay: Wistoria E3, Spy x Family E1 and a YouTube source decided on 10–11 heard windows with one or two lost). A refusal of this audio (a 400, the local service’s 500 decode error, a malformed answer) is not an outage and costs only its window, as before. An outage checked nothing (freshness._checked_sql), so the subtitles stay owed — the graph shows 判定 stale, clips wait — and the next mine queues the pass again (judge._auto_pass_failed, at most AUTO_ATTEMPTS per timeline, then the button). An unconcluded verdict stored over an outage before this rule (sync_run 140’s thin_lead) is read the same way; a decision stored over a few lost windows stays checked.

Checked is not confirmed. Checked keeps 判定 from running twice on the same subtitles; the latest check confirmed them only for apply, or leave_alone current_verified (freshness.subs_unconfirmed). The Sources list’s circle says when it did not (要確認, 判定できず, 未判定), and on the sync screen 保存 of the judged subtitles in use is the person confirming them. It holds no clip back (being judged never skips the clip scorer): every clip is scored and gated on its own — its score at the bar, lyric, 声が小さい, the music check (automine.clip_gate) — so a wrongly timed clip scores low and is held on that. Until 2026-11-05, with 判定 on for the kind, no clip of an unconfirmed source was scored (Vinland Saga S1E1, 2026-10-11: thin_lead, a clip sent with its tail cut, before the clip gates held every kind); new subtitles re-cut and re-score the clips anyway.

Applying. A constant offset against the timeline already playing goes through media.sub_offset_s, the control the viewer already has. Every other winner — a different file, a per-cue retiming, a stored .align.json — is a new cue set, materialised as a generated .srt and adopted through subtracks.adopt_subtitle_file. That file (judged-…srt, subtracks.cues_to_source_srt) is one cue per judged row with the row’s raw pieces as its lines. Every line starts with one invisible marker — U+2063 opens a piece, U+2064 continues it — because a raw piece can hold a line break of its own; the parser reads a marked judged- cue back as those pieces, so the row’s interval, its per-piece filtering, its sentence boundary and a piece’s own line breaks survive re-adoption and regeneration (#359, #363, #368). An unmarked judged- cue (written before the markers) is one piece, like any other file’s. The apply reads the written bytes back and refuses (winner_unavailable) unless they give the same intervals and text the winner derives to.

A verdict is a statement about the media as it was, so the write re-establishes all three identities before it happens, and each failure is a stored, named flag rather than a silent skip:

guard refusal what it stops
the winning file still hashes to what was judged (source_digest, carried from the bundle through tally into the verdict’s candidates) stale_evidence a re-pull between the judgement and the write being adopted under a verdict that never saw it
the media’s offset, selected file and live cues still match the bundle’s baseline baseline_moved a delayed −1.0 s landing on an offset an operator has since moved to 20 s
the evidence was gathered for this pass, or carries a baseline that can be checked replayed_evidence the read-only stored-bundle fallback (再判定) re-applying a correction on top of itself
the winner can be rebuilt from disk at all — present, readable and parseable winner_unavailable a guess in place of a file that has gone, and an OSError escaping with no flag anywhere
this exact bundle has not already written once (each stored bundle carries an evidence_id, recorded by the write) evidence_consumed a pending row that outlived its own apply being applied again: −1.0 s on top of −1.0 s
the generated .srt actually landed write_failed a full disk truncating the timeline that is playing

baseline_moved also applies to leave_alone: 現状維持 is a verification, and a timeline that moved after gathering is not the timeline that was verified. So does replayed_evidence — a bundle that carries no baseline names no timeline, so it can certify none. The no-candidate blind transcript is checked the same way — an operator who chose a subtitle in the meantime has already answered the question the pass was asking.

The write and its record are one transaction, across both stores:

  • the whole apply runs under BEGIN IMMEDIATE, so the baseline check and the mutation it authorises cannot be separated by another connection’s commit;
  • the adoption runs with commit=False, and the sync_run row, the consumption of the pending evidence and the write all commit together — a database that fails mid-record leaves no selection, no segments, no offset change and no consumed evidence behind, and the retry lands exactly once;
  • the .srt is staged: the bytes that were there are read first, the new ones land through a temporary file and os.replace (so a failed write cannot truncate the file it replaces), and anything that rolls the database back puts the file back too.

Provenance. The blind transcript, and any winner fetched from an ASR track, keeps origin='asr' on the rows it becomes, and the candidate pool reads judged- and blind-transcript.srt back as ASR. Without it the fallback returned to the next tournament as an ordinary subtitle file and the probe engine corroborated its own output. A current timeline that is itself machine-transcribed is therefore never certified: it lands on asr_unverified (要確認) until something independent verifies it.

A source playing its recognizer’s own transcript with no subtitle pool (freshness.own_transcript: segment origin asr on a platform whose Platform.subtitle_pool is False — a YouTube video with no captions or only YouTube’s machine captions, which are transcribed in full and mined, 2026-11-01) is therefore not queued for 判定 by itself and holds no clip, as a podcast’s transcript: there is no file for 判定 to choose. YouTube’s auto captions stay the media’s native source one switch away, and real subtitles adopted later are judged as usual. A kind with a pool (Stremio’s rung-3 transcript, a 字幕を生成 transcript) is still judged and held: its pool’s files can replace the transcript.

Undoing. A judged offset apply is exactly undoable and stamps the run with the baseline offset and an empty undo step, so 整列を取り消す restores the operator’s own offset. A judged adoption replaced the segment rows wholesale and cannot be walked backwards, so it is stamped undo_unavailable: the button is not offered, and a direct call refuses in as many words rather than reporting a success it did not perform.

Prerequisites. Two are required: a transcription runner (evidence.asr_source, 文字起こしの実行先: local, the default, is the probe_asr/ container at AM_PROBE_ASR_URL; openai or elevenlabs run in the cloud with that provider’s key; machine runs Whisper on this machine) and a ready judge (Jev with TYPESAFE_API_KEY, or the local judge, which needs no key). AM_SEPARATOR_URL is a degradation (the mix is probed instead and the reads say so). All three show in the 判定に使うサービス block on the Settings page (judge.prerequisites).

The mode is on or off, nothing between. sync.judge_mode (+ sync.judge_mode:<source>) is off (default) / on. Under on the judge runs (automatically, and from the 「音声で判定」 button) and applies its verdict. Under off nothing is judged: the button is taken away, POST …/sync/judge answers 409, the word pass computes no retime proposal, and the card shows no verdict recorded under any other mode. The handlers read the mode again when they start, so a sync.evidence or sync.judge job queued under on — or a failed one retried after the switch — settles skipped without gathering, asking the judge or recording a run; pending evidence stays for the next on pass (#431). Turned off during collection, the evidence is stored but no judgement is queued; turned off between model requests, no further request is sent and the pass is recorded as judge_mode_revoked with nothing written. The former shadow (judge and record, never apply) is retired; a stored shadow reads as an unrecognised value, i.e. off. The cutover bar was the replay of the incident set (Mushoku S3E9, Bleach E47/E48, Re:Zero S4E16, the アナクロニズム MV) plus one fresh series end to end with zero mis-applies, and the ladder was removed once it held.

The card describes the RUN (issue #314). Every stored verdict carries the judge_mode it was judged under and an applied_detail that only the apply path writes. GET …/sync returns a verdict only if it was judged under on, and the card states the application in the tense that happened: 一定のずれ -1.0s を適用しました versus …を適用していません (a write withdrawn because the mode was turned off mid-run). A record from before those fields existed reports its application as unknown rather than guessing.

A refused write is not a dry run (issue #314). _apply_refusal keeps the winner and its offset on purpose — the judgement was sound and it is the WRITE that fell over — which leaves a row shaped exactly like a withdrawn one: a winner, an offset, applied_detail of null. It is told apart by apply_refused, written by the refusal path and by nothing else, carrying the reason code, the writer’s own words and the verdict it replaced (flag alone does not say whether an apply, a materialised transcript or a 現状維持 certification is what failed). So the three write states are three sentences and never two: …を適用しました, …を適用できま せんでした (with the failure’s own text under it — No space left on device), …を適用していません (記録のみ). A refused 現状維持 reads 現状維持 を確認できませんでした rather than proposing an adoption nobody offered.

判定 is always available by hand. Pressing it is an explicit instruction and POST /v1/media/{id}/sync/judge honours it whatever the mode says — what the mode still decides is whether the verdict may ACT. So the panel is never hidden for the mode being off; the only thing that disables the button is a genuinely missing prerequisite, which the endpoint answers with a 409 naming the setting.

sync.reference_filters is one regex per line, applied to every subtitle track where its cues enter the working set — the file parse, the DB write, a subcache restore — never at display time. Each pattern is re.sub’d out of the cue text, and a cue with nothing left is dropped whole, interval and all. The starter list on the Settings page drops {\an8} signs, italic-only lyric lines and ♪/♬ music markers as whole cues, and edits (音楽)-style captions, 《ナレーション》 brackets, continuation arrows, doubled-paren inner monologue and speaker prefixes out of the cues that stay (#343, #347, #349). The raw files on disk are never rewritten, so changing or disabling the list and re-loading a track rebuilds the working set from the preserved source.

One filter, raw input only (#357). The patterns are written for one raw cue with its markup intact, and they are only ever applied to that (segments.derive_cues): filter, then strip markup, piece by piece. A segment row keeps the raw cue texts it was rolled from in source, a stored .align.json cue keeps the raw of the cue it retimes, and every reader — the judge’s candidate pool, the baseline fingerprint, the apply rebuild, a subcache restore, the source preview — derives the text it shows from those raws under the rules in force. Nothing re-filters a rolled sentence, a stripped line or text that was filtered once already; that is what made the current timeline diverge from its own file (#346, #350, #357). A row written before source existed has only its sentence and is re-filtered as one string until its timeline is stored again through any door.

A judgement takes minutes, and everything it writes describes the cue list it started from. On E48 a user’s revert landed mid-run and a sync_run row recorded a well-aligned reading about a timeline that was stored raw; the same window consumed the media’s hand-set +17.2 s, because prev_offset_s was re-read after the run, by which time an interleaving apply had zeroed it — and 0.0 is what the revert then restored.

So a pass reads the timeline ONCE (subsync.read_timeline) and carries a fingerprint of it — every segment row’s id, stored times and text, plus media.sub_offset_s:

  • prev_offset_s is the offset folded into those cues, never a later read of the media row;
  • the write and its sync_run row land in one BEGIN IMMEDIATE transaction that re-checks the fingerprint first (baseline_moved), so a pass can never apply itself to a timeline it did not judge;
  • revert makes the same check: the inverse it stores is walked off the current rows, so a repull, an adoption or a later apply in between is a 409 rather than a timeline that never existed. Rows from before the fingerprint column keep the old behaviour, exactly as they did.

POST /v1/media/{id}/sync/revert puts the rows back where the run found them and restores the hand-set offset. Runs written by the retired ladder carry a run-length-encoded block shift (blocks_json) and, since #161, the exact step back to the rows they overwrote (undo_json); revert still walks either, so an old applied run stays undoable. Like a sub_offset_s change (#142), an applied run queues no re-cut of its own: the media’s clips are stale and 再計算 / the re-cut button is what rebuilds them.

Measured words: where each line is spoken (words.py)

Section titled “Measured words: where each line is spoken (words.py)”

The judge decides WHICH timeline plays, from a sample of 8–12 windows. Clips, and anyone reading the cue list, need to know where EVERY line is spoken — most lines never fall inside a sampled window, and a derived offset or anchored retime moves a cue by its neighbours’ deltas, not by its own. So after a verdict that verifies the current timeline (leave_alone) or applies one, sync.judge queues sync.words, the dense pass:

  1. The current timeline’s rows are tiled into reads of at most 28 s (words.windows), each padded 1.5 s either side.

  2. Each read goes through the same instrument as the probe windows — MDX separation, then the probe recognizer with word timestamps.

  3. words.match_cues finds each line’s own opening characters in the timed words (longest run of 3–6 characters, nearest the cue, within 1.5 s), left to right so two lines never claim the same word, and ends the run at the line’s own tail or the last word it can own. A first word on the read’s leading edge, or a last word on its trailing edge, was cut off rather than measured, and is not stored. A line that finds no match within 1.5 s gets a second, wide pass: up to 15 s away, for a run of at least 6 of its own characters, and only after the last word of the placed line before and before the head of the placed line after. When the line before has no spelled ending (a respelled tail, so its run was cut at its cue end), the words its speech runs on into without a pause are still its, and the wide pass starts after them. A line whose run is also spelled by any line within 15 s of the read, in this window or the next, is not wide-placed at all: those words may be the other line’s, placed or not, and a wrong measurement is worse than none (the retime fills an unmeasured line from its neighbours).

    Each read also matches the line either side of its window, as context that is never written by that read. Without the next line’s head, the last line of a window ran on into the next line’s opening, and the same speech sat on two rows.

    When a written run still covers speech another row’s stored words cover (the next line’s opening was not recognisable in the earlier read: 電車残月 heard for 天鎖斬月), the contested words go to one row. They stay with the line whose own text they spell (its end, or its opening). When they spell neither, which happens with a kana respelling (イチゴ for 一護), they go to the line on whose side of the two cues’ boundary they were heard. A row that loses words is rescored on what it keeps. Words that spell both lines are two reads disagreeing about one word boundary, and they stay where they are.

    The wide pass is what measures a stretch of the timeline that is off as a block (Re:Zero S4E16’s cold open shows every line about 10 s before it is spoken, and the judge’s sample never looked there); such a line’s end is then searched relative to where its start was found. On the recorded reads of four episodes it gained 4 correctly timed lines and lost none.

  4. The matched words become segment_word rows (source = 'probe'), and the segment row gets heard_score (0–1, how much of the line the recognizer spelled) and heard_text (what it heard there).

  5. With sync.cue_verify on, the judge is then asked, per heard line, whether the line was actually said — matched by sound, so a kanji/kana respelling or a mangled name the character score undercounts still passes. The answer is heard_jev. The answers are written only once every batch is answered, so an interrupted or held pass writes none and the next pass asks every heard line again. When the judge errors (unreachable, rejected, a bad answer) the cue verify is held: the words job keeps the words it measured, but it does not retime, does not record the words version and keeps a pending remeasure request. It then waits on the job retry backoff (30 min, doubling to 6 h, failing after 3 days) with the judge’s reason, and the retry asks again without reading the audio a second time.

  6. The retime (words.retime_plan / apply_retime). Each heard line moves by its OWN error — its first word’s offset from its cue, minus the track’s typical lead (the median over every heard line), so the file’s style of showing a line a beat early is kept; corrections under 0.2 s are recognizer jitter and ignored. A line nobody heard moves by the median of its 7 nearest heard lines’ corrections (anchored_retime’s rule, over dense anchors instead of 12 windows), which is what follows a staircase to its real edge. A line that now starts inside the one before it trims that one’s end. Lines the judge said were not spoken are left out of the measurement. The write is in place (ids, word rows and candidates stay linked), only under 判定モード on, only if the timeline is still the one measured, and as an applied probe-retime run whose undo_json holds each moved row’s previous times, so 整列を取り消す restores it exactly. Legacy forced-alignment words (cue-relative) move with their line and their exact previous times are in the undo too (#386); probe words (audio positions) never move. The plan is recomputed under the write lock and must match the one that was proposed. Under off the job writes nothing and reports no proposal. On S3E9: 172 of 267 lines moved (median 0.39 s, max 1.15 s), after which all 208 heard lines sit within ±0.2 s of the track’s lead.

Every write is bound to what was read (#385). A measurement lands only on a row that still has the same stored times, text and media offset as when its audio was read, and a judge’s answer only on a row that also still holds the same heard text. The check is part of the UPDATE itself, so a track replaced during a read (SQLite reuses the rowids), an edited line or an offset change gets nothing; the other lines of that read keep their progress. Only rows with no measurement are written: lines in a read that were already measured, and neighbours read for context, keep their words, score and judge’s answer (#388). Windows whose lines are all measured are skipped, so re-judging a verified media costs no audio and an interrupted pass resumes. A cut of a line no pass has measured yet (words.measure_around, called from assets.clip_window(probe=True)) reads once over the WHOLE candidate span, anchor through a merged run’s end, plus its two neighbours, and skips the read only when every row of the span is measured. A span longer than one read (28 s) is read in chunks overlapping by 2 s, each keeping the words centred in its own part. POST /v1/media/{id}/sync/words queues the pass by hand. {"remeasure": true} reads every line again, and is a durable request, not a reset (#396): a token written in the same transaction as the job, nothing cleared up front, each line’s measurement replaced only when its new one lands. A pass already queued or running picks the token up before it finishes and goes round again, so a request made mid-pass is never answered by the older pass; the token is consumed only after every window was read, so a remeasure that fails or is cancelled stays pending and every old measurement stays standing.

The job ends in ONE write transaction that checks for a cancel, checks for a remeasure requested during the round, writes the retime and marks the job done (#395). A cancel is recorded under the same write lock, so a cancel before that transaction stops the retime (the measurements already committed are kept, and a retry resumes from them) and a cancel after it finds a finished job whose retime and status agree. The judge queues this job inside its own commit (#397), so an applied or verified timeline and its measurement pass commit together: a queue that refuses the insert rolls the judgement back whole, and the retry judges and applies the same evidence once instead of refusing its own write as baseline_moved.

GET /v1/media/{id}/cue_scores is what the sync screen’s cue list shows as a badge per line: the score, and where the first word was heard relative to where the line shows. The badge belongs to the current timeline only (#389): it is drawn only when the list shows the media’s own segments, only on a cue with the same start (in the milliseconds the VTT prints, t0_ms) and the same text, each (start, text) pair taking its own measurement in order so lines sharing a start keep theirs (#392), and a reply that arrives after the view changed is dropped. The gap is computed on the page against the offset on screen, an unsaved nudge included (the tooltip says so), and repainted whenever that offset changes.

A line the recognizer cannot hear (SFX, a song, a mumble) gets no word rows and a low score, and every reader falls back to display timing for it. That is the honest answer, and the score makes it visible.

The word rows are what clip boundaries read (layer 0 — clip-trimming.md). Probe rows are AUDIO positions: a manual offset change moves the subtitles, not the speech, so it leaves them where they are. A door that REPLACES segment rows deletes them (they describe rows that no longer exist, and segment_word.segment_id points at the rows being deleted).

Clip timing reads the word rows directly, so it does not depend on the retime; the retime is for what is SHOWN.

The ElevenLabs forced-alignment provider this replaced was retired unused: its per-sentence “garnish” caller was never written. Rows it wrote on earlier runs still time clips when their run was applied.

key meaning
sync.judge_mode (+ :<source>) off (default: nothing is judged) / on (the judge runs and applies)
sync.probe_windows 聞く区間の上限 — probe windows per pass (default 12, floor 3, ceiling 48)
sync.reference_filters the load-time filter list, one regex per line; no row means off
sync.separation (+ :<source>) off (default) / local / proxy — MDX vocal separation for the probe windows and the whole-file speech scan
evidence.asr_fallback off by default; on, a cloud ASR key may stand in when no local probe service is configured
asr.provider openai (default) / elevenlabs / off (文字起こししない, “No transcription”) — picks the transcription client; local is still accepted but not offered, and is refused (see below)
sync.cue_verify off by default; on, the dense pass also asks the judge whether each heard line was said (heard_jev)
asr.model:<provider> the model each provider is called with; blank = that provider’s default (asr.model remains the OpenAI one)
judge.backend jev (default) / local: which judge answers all five judge tasks. Any other value is refused (422). Choosing local queues its download if it is not ready. Without a Jev key the local judge answers whatever this says, and the row is left as it is. The control is 設定 › サービス › 判定サービス
budget.daily_usd, budget.monthly_usd, budget.source_usd, budget.margin_usd the spending limits (costs.py): a paid call (ASR, a probe read, a translation) that would leave less than the margin under one is refused and its job held (予算待ち); asr.max_min_per_day was converted into budget.daily_usd once and retired

All are ordinary settings rows, read hot, with controls on the Settings page under 字幕の同期 (issue #225 moved the ASR model, 翻訳 and the API keys out to the AI 連携 tab, and asr.provider moved there with them — it now sits on the 字幕の音声認識 card beside the per-provider models it selects, so there is one control writing that row rather than two).

asr.provider is read by asr.resolve_provider, which both transcription call sites use — asr.handle_asr and fetch_stremio.asr_segments — so the two cannot disagree about which back end ran or which key was missing. local has no client and is refused by name (no_provider) rather than falling back to OpenAI, because a silent fallback makes a paid call look free.

Only providers that DOCUMENT their timestamps transcribe here — Whisper’s verbose_json segments, Scribe’s words. Gemini is not an ASR option: it has no transcription endpoint, so a transcript’s start/end seconds would be predicted text rather than a measured response field, and assets.word_bounds cuts clips from those timings — a plausible-but-wrong timestamp is a miscut clip that looks correct in the database. Translation has its own switch under translate.provider (OpenAI or Gemini), where there is nothing to align; ElevenLabs is absent there, being a speech API. The separation and judge mode rows have per-source overrides (#207): an empty key:<source> row means “inherit the shared value”.

autominer judge fetch downloads a pinned llama.cpp CPU build (b12529) and one judge model into $AUTOMINER_HOME/judge (see “Judge models ranked by the host” below for which one). On Windows and Linux x86-64 with a Vulkan loader (vulkan-1.dll, libvulkan.so.1) it also downloads the same build’s Vulkan variant (about 39 MB), pinned the same way, before the model, so the model can be picked for the GPU. A machine without the loader never downloads it. The Vulkan build is optional: the judge is ready as soon as the CPU build, the model and the license are. A Vulkan download that fails still lets the model download, ranked as for a host without a GPU, and then fails the fetch with the Vulkan error. The judge.fetch job adds a missing Vulkan build later (every start queues the job while the local judge is in use: wanted, or ready and the chosen judge).

  • Checks: every file’s SHA-256 is checked before it is kept. The archive is unpacked only if every entry stays inside the folder.
  • Manifest: ready.json lists every unpacked CPU-build file and its size. The local judge counts as ready only while all of them, the model and the license are still there at those sizes. gpu.json does the same for the Vulkan build, which is used only while it holds.
  • Re-running: hashes.json records each file the run verified, with its size, mtime and SHA-256. A second run trusts that record while the file’s size and mtime still match, hashes again only a file that changed, and downloads nothing that is intact. It unpacks a build again only if one of that build’s own files has gone, so a build a running server uses is left alone.

With the local judge in use, the first judge question of a process starts one llama-server on a free localhost port.

  • Alias: the alias is unique to the judge model and the home. server.json records the server’s pid and port, so a server left running by a killed process is reused rather than started twice.
  • GPU (#1513): when the Vulkan build is intact and its --list-devices names a GPU, the server starts from it with llama.cpp’s own offload defaults (-ngl auto with --fit). It must be healthy within GPU_TIMEOUT_S (20 s) or the model’s size read at GPU_LOAD_BYTES_PER_S (30 MB/s), whichever is longer (37 s for d1-2B, 90 s for h2o-lightning-4B, which took 54 s cold and 30 s warm on an RX 9070 XT), and answer a two-question self-check correctly twice, the second time within GPU_SELF_CHECK_MAX_S (0.5 s), so a GPU that is not clearly faster than the CPU is not used. If no GPU is listed, or the GPU server fails any of that, or a GPU server this process started dies, the CPU build runs for the rest of the process. A Vulkan build that is missing or broken is skipped the same way, and one that arrives later is used from the next server start. Apple silicon’s CPU build already uses Metal.
  • Restarts and stops: a server that dies under a question is restarted once. The process stops the server when it exits.
  • Cool-down: a start that fails is not retried for START_COOLDOWN_S (5 minutes). Questions asked during that time get the same reason straight away.
  • Sizing: the server runs one slot with 4096 tokens of context and batch, and no prompt cache. Each request is capped at 12,000 bytes. One request carries one row (a window, a cue, a line pair or a sentence), because d1-2B mixes up rows in a batched state. The server answers up to 16 questions on a row in one pass.

Every local failure holds the task with a local_judge_* reason:

  • missing and runtime_missing (Windows needs the Visual C++ 2015-2022 runtime)
  • not_started, not_decision_model and unreachable
  • request_too_large, rejected, failed and bad_answer

Switching the backend or the judge model re-judges nothing. Cached answers stay, including the sentence_quality verdicts. Each of those records the judge that answered it (judge: jev or local; rows from before have none and count as Jev), and a local one also records the judge model (judge_model, such as d1-2B; local rows from before #1536 have none and came from d1-2B, the only model then). A reused verdict keeps its own judge. The line-join and cue-verify caches record no judge, so they record no judge model either.

A run resolves the judge once (judge_service.one_judge) and uses it for every call. A sentence-quality pass, a 判定, a line-join pass and a cue verify never switch judges halfway, even if the key is saved or deleted while they run. The run pins the judge model it started with too, and that is the one its cached answers record.

The local judge offers several judge models (local_judge.MODELS, most accurate first), each pinned by SHA-256 with its licence file saved beside it. A model joins the list only with a committed replay report (bench/judge-replay/). One model is on disk at a time.

Judge model File Licence Free VRAM it needs
h2o-lightning-4B h2o-lightning-4b-Q4_K_M.gguf, 2.7 GB Apache-2.0, saved as h2o-lightning-4b-LICENSE 3640 MiB
d1-2B d1-2B-Q4_K_M.gguf, 1.1 GB LFM Open License v1.0, saved as LICENSE 2000 MiB
  • Ranking (local_judge.ranked). A model is fast here when its timed check measured at most SENTENCE_BAR_S (1 s per new sentence, ADR-0002’s bar), or, before it is measured, when the GPU that --list-devices lists first has the free VRAM it needs. Fast models come first, most accurate first; the rest follow smallest first, so a host without a fast model gets the smallest. Every host has that floor model.
  • The host (host.json). Each fetch lists the GPUs and records the hardware (the CPU, and each GPU without its free MiB), the free VRAM and each model’s measured seconds. The measurements and the free VRAM are kept while the hardware stays the same, and start again when it changes. A listing that fails (it times out, exits non-zero or cannot start) is no hardware change: the last known GPU stands until a listing succeeds and differs. A listing that succeeds and names no GPU is a change.
  • Measuring once more. A measurement over the bar is doubted once, at the next fetch, when its check ran on the CPU while a GPU was listed (the GPU was busy at the time) or when it is older than REMEASURE_AFTER_S (30 days). A doubted model is ranked by its free VRAM again, as before it was measured, and is checked again when that makes it the model to fetch. Its number still shows until then. The new measurement replaces it and is not doubted again until the hardware changes. A measurement within the bar is never doubted, because a busy machine only makes a check slower.
  • A missing GPU build. A host with a Vulkan loader whose Vulkan build is missing or broken cannot list its GPUs, so that is no hardware change either. A host without a loader, or without a pinned Vulkan build, has no GPU.
  • Timed check (local_judge.timed_check). After a download, 21 fixed questions (judge_check.json: window kind, line joins, three sentences of sentence quality, cue verify) run on a second llama-server of their own, on the device the normal start would pick, with its own log (check.log). Seconds per new sentence is the time of the sentence-quality requests, the replay’s measure. They come first, after one untimed sentence that warms the server up (the first request on a fresh Vulkan server took 2.2 s against 0.2 s after it), and a check over twice the bar after a sentence stops there. The server the judge uses keeps answering meanwhile.
  • Who picks. judge.model holds the learner’s pick; without it AutoMiner picks the top model. A switch downloads the new model next to the old one, checks it, and only then writes it into ready.json, stops the server and deletes the old files. AutoMiner’s own candidate that misses the bar is deleted and the next model down is tried. The first model of a fresh install is checked before it is used too, except the floor model, which answers at once and is measured after. A learner’s pick is kept whatever its speed.
  • A check that fails. A timed check that raises (its server cannot start, or answers badly) counts as a failed check. The model is deleted unless it is the one answering, the next model down is tried as for a slow one, and the fetch then fails with the reason (judge_service.reason_message), so the judge.fetch job shows it as failed. A learner’s pick whose check fails stays the pick (judge.model, picked_by: user), but it is not fetched: AutoMiner’s top model answers and the card shows that one as ready. host.json records the failure, so no start checks that model again. Choosing local, pressing download or picking a model forgets the failures, and so does a hardware change.
  • Hardware changes. Every server start queues judge.fetch while the local judge is in use: wanted, or ready and the chosen judge. A keyed install that holds the local judge but judges with Jev, and never asked for it, lists no devices and downloads nothing at a start, so its delete is never refused by a start’s fetch. When the hardware differs from host.json, AutoMiner’s own pick is ranked again and switched if the top model changed. A learner’s pick stays. An install from before #1536 that holds d1-2B and has no judge.model counts as AutoMiner’s pick.
  • Keys. An install without a Jev key judges with its top model, whatever its speed. An install with a key stays on Jev: no judge model passes the agreement half of the gate.

The Judge card’s 判定モデル row is a select of the models in this ranked order, “name · size”. While ready, the device text beside it is coloured by the current model’s measured speed here: ok at or under the bar, warn up to twice the bar, err beyond, and the plain status colour before it is measured. During a switch the select shows the new model beside the download bar.

Choosing the judge and downloading it in the app (#1492)

Section titled “Choosing the judge and downloading it in the app (#1492)”

The app downloads the local judge in a judge.fetch job (key local), with the same checks as autominer judge fetch. The job shows on the Workers strip, and jobs.request_cancel stops it.

  • Resuming. An interrupted file keeps its .partial. The next run asks for the rest with an HTTP Range request and appends a 206 whose Content-Range starts at the partial’s size. A 200, or a 206 for another range, means the origin cannot resume: the file is downloaded again from byte 0 (step redownload). The whole file’s SHA-256 is checked either way, and a resumed file that does not match is downloaded again from the start.
  • Sharing the worker. After FETCH_SLICE_S (30 s) of downloading, the job queues itself again behind a job the worker would claim before it (jobs.waiting_ahead: the same or an earlier lane, not waiting on another job) and resumes from the partial. It pauses only between download chunks: never while checking a file, and never during a redownload. A restart puts a running judge.fetch back in the queue (RESUME_KINDS).
  • Intent. Choosing local or pressing download records judge.local_wanted. While it stands, every server start queues the download again if the judge is not ready. 中止 and 削除 clear it and discard the partials, so a restart does not undo them. A running job discards its own partials when it sees the cancel; with no job running they are discarded at once, and a file still in use is left and logged. A download pressed again while the cancelled job is still stopping withdraws the cancel, and if the job stops anyway it is queued again once it settles. A stop from the Workers strip stops this run only: the intent and the partial stay, and the next start resumes.
Route What it does
GET /v1/judge the chosen judge and the local judge’s state
PUT /v1/settings/judge.backend {"value": "local"} chooses the judge; local records the intent and queues the download if it is not ready. The answer carries judge, the same state
POST /v1/judge/local/fetch records the intent and queues the download; a second press while one is queued or running, or once ready, queues nothing
PUT /v1/judge/local/model {"model": "d1-2B"} records the learner’s pick (judge.model, any case of a listed name; anything else is 422), forgets failed checks and, while the local judge is in use, queues the switch. A pick changed during a download hands the job over to the new pick
POST /v1/judge/local/cancel with nothing installed, clears the intent; during a switch, keeps the model that answers as the learner’s pick and deletes the new one’s files. Either way it cancels the job; the partials are discarded by the job, or at once when none is running
DELETE /v1/judge/local clears the intent, stops the server, then deletes $AUTOMINER_HOME/judge; refused (409) while a download is queued or running, 500 if a file cannot be removed. A queued judge.fetch with nothing left to download (a start’s probe of a ready judge) is cancelled instead

GET /v1/judge answers:

{"backend": "local", "name": "このマシン", "available": false,
"reason": "local_judge_downloading", "problem": "このマシンの判定をダウンロード中です",
"jev_key": false,
"local": {"models": [{"model": "h2o-lightning-4B", "size": 2708808736, "s_per_sentence": null},
{"model": "d1-2B", "size": 1099629888, "s_per_sentence": null}],
"picked_by": "auto", "bar_s": 1.0,
"model": "h2o-lightning-4B", "state": "downloading", "step": "download",
"done": 52428800, "total": 2773371386, "cancelling": false, "wanted": true}}
  • local.models are the judge models in this host’s ranked order, with each one’s measured seconds per new sentence here (null before its timed check). picked_by is user when judge.model names one, else auto. bar_s is the speed bar.

  • local.model is the model that answers while ready, and the one being fetched otherwise.

  • backend is the judge in use: local when judge.backend is local or no Jev key is set, otherwise jev. jev_key says whether Jev can be chosen. Only a key that is not configured at all counts as no key. A key that is set but cannot be read (an unreadable file, a TYPESAFE_API_KEY_FILE that is gone) keeps Jev, which holds with no_jev_key.

  • local.state is one of four values. Each carries model, total and wanted.

    • missing.
    • downloading, with step (checksum, download, redownload, unpack or check, or null while queued), done and cancelling.
    • ready, with threads, checking (a judge.fetch job is queued or running, such as the timed check after a start; the card polls until it ends) and device: the GPU the running server uses (before it starts, the device the model’s timed check ran on), "" when it runs or will run on the CPU (no Vulkan build, or the GPU was given up), or null when a Vulkan build is there but no server has started yet and no timed check has run here. The download can still be adding the Vulkan build then.
    • failed, with error, the job’s message.
  • reason and problem are the judge in use’s: local_judge_missing, or local_judge_downloading while the job is queued or running. A keyless install holds with these, never with no_jev_key.

  • The 判定 prerequisite row (key judge, in /v1/sync/prerequisites and the source page’s services) carries progress ({step, done, total}) while the download runs.

While the chosen judge is not ready, judge tasks hold rather than fail:

  • Parked jobs. A cue verify or a sync.judge whose question gets a not-ready reason (no_jev_key, local_judge_missing, local_judge_downloading), and a sync.evidence pass that finds the judge missing, park with judge_service.JudgeHeld (retry.cause judge). No verdict is recorded and no attempt is spent. A judge hold never reaches the 3-day give-up. Any other judge error in a cue verify keeps #1512’s RetryLater, with the normal backoff and give-up.
  • Owed 判定. A mined source that would get its 判定 auto attempt but for the judge is marked sync.judge_owed:<id> = <rev>. The attempt counter sync.auto_judged:<id> is not touched. An auto attempt that runs clears the marker.
  • Line joins are not asked.
  • Sentence quality falls back for that mine run. Nothing re-runs it when the judge becomes ready; the next mine uses the judge.

The held work is released when the download finishes, when the learner chooses a judge that is ready, when the Jev key is saved or deleted, and on every server start. It is released only if the chosen judge is available then:

  • the jobs parked with retry.cause judge are made due;
  • the line-join sweep is queued;
  • each source marked sync.judge_owed: gets its auto attempt under the usual rules, and the marker is cleared.

Work held for any other reason keeps its hold. That includes 判定 refusals recorded before this change, such as old no_jev_key refusals, which saving a key does not re-run. A release that fails after the setting or key is saved is logged, and the work waits for the next trigger.

Selecting a card used to be the switch for some card kinds and a preview for others, and one active flag answered three different questions at once. The rule now is the same for every origin — jimaku, upload, embedded stream, the media’s own captions, the transcript:

  • a click previews. It changes the highlight, the cues, the search and the controls. It sends no source-switch request, replaces no segment rows and saves no selection; leaving the page loses the choice;
  • 保存 is the only adoption. It commits the previewed subtitle and the timing on screen — through POST /v1/media/{id}/subtitle_file for a file, POST /v1/media/{id}/subtitle_source for a segment-row source — and 使用中 moves only after core says the write happened;
  • preparation is not adoption. POST /v1/media/{id}/subtitle_preview answers how to READ a card ({"name": …} / {"track": …} / {"source": …}, the parameters /v1/media/{id}/subtitles takes) or queues the one preparation that is not a read — extracting an embedded stream, which lands as a plain .srt and stops (payload.adopt: false). A native/ASR source that has never been produced answers {"status": "produce"}: making it writes the timeline as it runs, so the screen asks for it in those words rather than doing it because a card was clicked.

Two separate facts, two separate sources of truth:

fact comes from drawn as
previewed the page’s own sync.previewKey the card highlight
saved media.subtitle_file, per card as saved 使用中

Each card also carries subtitle_id — file:<stored name> for anything that is a file, source:<key> otherwise — so a jimaku candidate and the copy of it already on disk are one subtitle, and identity survives a listing that reorders itself.

One subtitle-status tag, 使用中 — the subtitle the media uses. It stays put while another card is previewed and moves only after a successful 保存. Group headers are disclosure controls and carry no tag; loading and extraction progress is shown, as progress. The judge’s verdict is the decision card on the sync panel, about the media, never a tag on a card.

An applied run belongs to its subtitle. sync_run.target names the file a run was about, media.sync_json.target carries it onto the media verdict, and an adoption that replaces the timeline clears that verdict (subsync.drop_media_state) rather than letting it be read as the new subtitle’s own. 整列を取り消す acts on the subtitle the line describes: an applied run is reverted with {"file": …} (a mismatch is a 409 and nothing is written).

The judge’s first rank is not always the viewer’s pick, and a raw file adopted by hand loses what the judge measured (Wistoria E2 stayed at 0.0 s although -0.53 s was measured). So the card list opens with a group 判定の候補: every ranked candidate of the newest gathered run (judge_pick.candidates), each saying how it was tuned (an offset, a per-line retime or none), its rank and its lines placed and heard. A click previews it as an adopt would write it (/subtitles?judged=…, absolute times, played at offset 0); 保存 posts {"judged", "run_id"} to /subtitle_file, which adopts it through judge.apply_verdict (the same file, timeline or offset) and records a sync_run (tool judge, verdict apply, reason person_choice, chosen_by: "person", its baseline’s subs_gen the generation it leaves). That row is a passed 判定 for those subtitles: subs_judged holds, so the pass is not run again, and the clip gate reads it as confirmed. A form of the timeline that WAS playing is offered only while it still is. The raw files stay below, as before.

route does
GET /v1/media/{id}/sync the offset, run history, whether a revert is possible, the judge’s own verdict (judge), judge_mode, services (the three prerequisites with live status, so the decision card can name a missing one instead of rendering blank) and picks (every ranked candidate of the newest 判定, for the picker)
POST /v1/media/{id}/sync/judge queue the sync judgement (#307): {"mode": "sampled"|"full", "reuse": true} — reuse re-judges stored evidence with no audio. 409 when 判定モード is off, or naming the missing prerequisite rather than queueing a job that can only fail invisibly
POST /v1/media/{id}/subtitle_preview prepare one card for PREVIEW without adopting it (#183): {"status": "ready", "read": {…}} / queued / produce
GET /v1/media/{id}/subtitles?name=…|track=…|source=… the cues of any subtitle this media holds, as a read — a file on disk, a jimaku candidate, a cached native/ASR source
POST /v1/media/{id}/sync/revert undo the last applied run, restore the manual offset (optional {"file": …} names the subtitle being undone; 409 when there is nothing to undo, when the run is a different subtitle’s, when it was an adoption that cannot be walked back, or when the timeline is no longer the one that run left behind)
GET /v1/sync/reference-filters which filter patterns compile, and which Python refused

YouTube: a transcription ladder, not a sync rung

Section titled “YouTube: a transcription ladder, not a sync rung”

YouTube inverts the problem — auto-caption timing is fine, the text ranges from passable to garbage. The first rung of that ladder is in this change: fetch_yt.fetch_subtitles now pulls the creator’s uploaded track and YouTube’s machine captions separately (manual first), so segment.origin is finally the truth about where the text came from (sub vs auto-sub). Everything downstream of that — scoring auto-captions for sentence cleanliness, escalating the measured-bad ones to real ASR, and keeping what stays bad in a low trust tier — is issue #141’s cleanliness score and is not implemented here; the provider setting and the per-source cost cap it will spend against are.

subsync.detect_speech is the whole-file speech scan the judge snaps its probe windows onto (evidence.plan_windows), and separation.py hands it separated vocals when sync.separation is on. It calls autominer.vad.speech_spans: the same torch-free onnxruntime detector the clip trimmer runs (#145), over the same ONNX graph, with the same “missing → say so, never guess” contract — deliberately not the silero-vad pip package, which is torch, is declared in no extra and whose read_audio cannot read audio at all under torchaudio ≥ 2.9 without torchcodec. So:

  • install is pip install -e 'core[vad]' (onnxruntime CPU + numpy) plus the ~2 MB model at $AUTOMINER_HOME/models/silero_vad.onnx — the exact same two things clip trimming already needs, nothing extra;
  • no_vad means the model file is missing, identically to the trimmer’s detector_fallback reason. no_ffmpeg stays its own code;
  • an episode is scanned in ≤ 120 s windows (vad.MAX_PROBE_S) and the spans stitched back together, so no whole-episode wav is written to the Pi’s 899 MB tmpfs. A window that cannot be read is vad_failed, never a silently shorter scan;
  • a scan that cannot run costs the pass evenness, not the pass: window planning falls back to the raw grid.

The scan holds silero’s own get_speech_timestamps defaults (min_silence_ms=100, min_speech_ms=250, speech_pad_ms=30, threshold 0.5) rather than reading the assets.vad_* rows: tuning where a clip gets cut must not move where the judge thinks somebody is speaking.