Ground truth text alignment (--ground-truth)#33
Merged
Conversation
Replace Whisper's approximate transcription with the real book text
while preserving word-level audio sync via Myers diff + Jaro-Winkler
fuzzy matching. Auto-detects markdown / plain text / structured-JSON /
bulk-JSON ground-truth inputs.
New crate `dpub-align` (~1000 lines, 44 unit + 1 integration test):
- normalize.rs — Unicode-aware lowercase + punctuation stripping
- diff.rs — Myers diff via `similar` 3.x with Jaro-Winkler ≥ 0.85
fuzzy promotion (catches "Antwerpe" → "Antwerpen")
- boundary.rs — Anchor detection (≥5 consecutive matches) classifies
ops as Leading/Core/Trailing so audiobook preambles
and outros never smear into the first/last real word
- transfer.rs — Timestamp transfer with three boundary strategies
(Drop / NoSync / Bracket), monotonicity enforcement,
character-proportional interpolation for inserts
- section_split.rs — Markdown vs plain-text auto-detect; fuzzy heading
matching against DAISY NCC titles
- json_format.rs — Structured (per-chapter) and bulk (whole-book blob)
JSON formats; pass-through with NBSP normalisation
CLI:
- --ground-truth <PATH> (requires --transcribe)
- --ground-truth-strategy <drop|no-sync|bracket> (default: no-sync)
- Config file fields `ground_truth` and `ground_truth_strategy`
Bug fixes surfaced by end-to-end testing on a digit-prefixed DAISY book:
- OPF manifest IDs now prefixed with `s-` when stems start with a digit
(XML Names cannot start with digits — broke any DAISY book with
`001_*.smil` filenames; the reference book happened to use letter
prefixes so nobody noticed).
- Empty `<seq>` elements no longer leak into Media Overlay SMIL files
(EPUBCheck RSC-005). Empty paragraph wrappers are skipped at the
builder layer; the SMIL writer also defensively drops recursively
empty seq subtrees; the heading-level overlay shell is preserved
when alignment would have produced an entirely empty word tree.
- Words that round to the same millisecond as their neighbour no
longer ship in SMIL (EPUBCheck MED-009). The builder mirrors the
writer's millisecond rounding when filtering zero-duration words.
End-to-end verified on "De verwarde Cavia" (109 sections, 4h22m
audio): 103/109 sections matched, 209 boundary trim events recorded,
final EPUB passes EPUBCheck clean (0 fatals / 0 errors / 0 warnings).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dpub-align(~1000 lines, 44 unit + 1 integration test) — testable in isolation, no whisper.cpp build dependency.--ground-truth <PATH>(requires--transcribe);--ground-truth-strategy <drop|no-sync|bracket>controls how book-only material (colophon, index) is handled.Bug fixes surfaced during end-to-end testing
s-when the stem starts with a digit. XML Names cannot start with a digit, so any DAISY book with001_*.smilfilenames previously failed EPUBCheckRSC-005. The reference book happened to use letter-prefixed filenames so the bug was latent.<seq>elements no longer leak into Media Overlay SMIL (EPUBCheckRSC-005). Builder skips empty paragraph wrappers; SMIL writer defensively drops recursively-empty subtrees; the heading-level shell is preserved when alignment would produce an entirely empty word tree.MED-009). The builder mirrors the writer's ms rounding so two distinctf64timestamps that collide post-rounding can't ship asclipBegin == clipEnd.End-to-end verification
Tested on De verwarde Cavia (109 sections, 4h22m audio) with the bulk-JSON ground truth:
"Einde van het boek"correctly caught as a Whisper-only outro)Test plan
cargo test --workspace— all greencargo run --example match_sectionsdry-run dependency-free🤖 Generated with Claude Code