braidio.textprep#
Text preparation for scripts — clean OCR’d source, tidy authored lines.
Small, reusable helpers a commentary production reaches for repeatedly:
clean_ocr()— normalize text extracted from PDFs/scans (ligatures, soft-hyphens, doubled hyphens, whitespace) so a TTS voice reads it cleanly.strip_speaker_labels()— drop a leaked"Host: "/"Chris: "prefix that a writing model sometimes prepends and that would otherwise be read aloud.
These were duplicated in ad-hoc rendering scripts; they belong here so any consumer (Hamilton and the next app) shares one implementation.
Module Attributes
Latin ligatures that OCR emits as single code points. |
Functions
|
Normalize OCR/PDF-extracted text for clean narration. |
|
Remove a leading speaker-label prefix (e.g. |
- braidio.textprep.LIGATURES: dict[str, str] = {'ff': 'ff', 'fi': 'fi', 'fl': 'fl', 'ffi': 'ffi', 'ffl': 'ffl', 'ſt': 'ft', 'st': 'st'}#
Latin ligatures that OCR emits as single code points.
- braidio.textprep.clean_ocr(text, *, collapse_whitespace=True)[source]#
Normalize OCR/PDF-extracted text for clean narration.
Expands ligatures, removes soft-hyphens (used at scan line-breaks), turns a doubled hyphen
--into an em-dash (so TTS phrases it as a pause), and (by default) collapses runs of whitespace to single spaces.- Return type: