Skip to content

fix: join hyphenated and line-wrapped words for TTS - #44

Merged
arphen merged 1 commit into
mainfrom
fix/tts-dehyphenate-line-wraps
Aug 22, 2026
Merged

arphen merged 1 commit into
mainfrom
fix/tts-dehyphenate-line-wraps

Conversation

@tomazzinko

Copy link
Copy Markdown
Collaborator

Summary

  • TTS was speaking words like "evo- lution" as two separate utterances. Two independent causes: tokenizeForRSVP splits any hyphenated compound for RSVP display, and sentences.ts rejoined the pieces with a naive space-join; and line-end hyphens from hard-wrapped source text were only repaired on the EPUB path, and only when the joined form was already attested elsewhere in the book.
  • sentences.ts now suppresses the space after a -// continuation token when rebuilding utterance text.
  • New shared src/core/ingest/lineWrap.ts resolver decides, per line-end wrap, whether to join and whether to keep the hyphen (soft hyphen, digits/number-words, book-local attestation, capitalization, and a short safe-prefix list), defaulting to join-and-drop when unresolved.
  • Wired into EPUB (replacing the old EPUB-only, attestation-only repairHardWraps), PDF (including cross-page-boundary wraps), and the previously-unrepaired TXT and Markdown readers.
  • Fixed two latent bugs found along the way: a successful wrap join used to inject a spurious paragraph break, and U+00AD soft hyphens were unhandled anywhere in the codebase.

Test plan

  • npm test — 842 tests pass, including new coverage in lineWrap.test.ts, contentQuality.test.ts, pdfReader.test.ts, pdfLayout.test.ts, sentences.test.ts, and new plainTextReader.test.ts / markdownReader.test.ts
  • npx tsc --noEmit clean, npx eslint clean
  • npm run inspect:epub on public/pg1952-images.epub confirms a real hard-wrap join ("a + long -> along") with no spurious issues introduced

TTS spoke words like "evo- lution" as two utterances. Two causes:
tokenizeForRSVP splits any hyphenated compound for RSVP display, and
sentences.ts rejoined the pieces with a naive space-join; and line-end
hyphens from hard-wrapped source text were only repaired on the EPUB
path, and only when the joined form was already attested elsewhere in
the book.

sentences.ts now suppresses the space after a continuation token. A
new shared lineWrap.ts resolver decides, per wrap, whether to join and
whether to keep the hyphen (soft hyphen, digits, book-local attestation,
capitalization, and a short safe-prefix list), and is wired into EPUB,
PDF (including cross-page wraps), and the previously-unrepaired TXT and
Markdown readers.
@arphen
arphen merged commit 272c50d into main Aug 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants