Assembles EPUB3 packages with Media Overlays for word-level audio synchronization.
Source: screencastgen/epub_builder.py
Generates standards-compliant EPUB3 files with Media Overlays (SMIL). Each word in the text is individually timed to the audio, enabling reading systems to highlight words as they are spoken.
EPUBBuilderEPUBBuilder(title: str, language: str = "en-US")
| Method | Description |
|---|---|
add_chapter(chapter_num, aligned_chunks, lipsync_video_path=None) |
Add a chapter with audio-synced text (and optional video) |
build(output_path) -> str |
Assemble and write the EPUB file |
| Method | Description |
|---|---|
_build_xhtml(ch, video_name) -> str |
Generate chapter XHTML with <span> per word |
_build_smil(ch, audio_map) -> Tuple[str, float] |
Generate SMIL Media Overlay with word-level <par> elements |
_build_toc() -> str |
Generate navigation document (table of contents) |
_build_opf(manifest_items, spine_items, total_duration, chapter_durations) -> str |
Generate OPF package document |
-epub-media-overlay-active CSS class for active word highlighting<par> elements with <text src="...#word_id"/> and <audio src="..." clipBegin="..." clipEnd="..."/>media:duration metadata for each chapter and totalEPUB Builder
├── zipfile (stdlib)
├── Types (AlignedChunk, WordTiming)
└──▶ consumed by Highlight Pipeline
└──▶ consumed by Lipsync Pipeline
output.epub (ZIP)
├── mimetype
├── META-INF/
│ └── container.xml
├── OEBPS/
│ ├── content.opf
│ ├── toc.xhtml
│ ├── style.css
│ ├── chapters/
│ │ ├── chapter_001.xhtml
│ │ ├── chapter_001.smil
│ │ └── ...
│ └── audio/
│ ├── audio_chunk_0001.mp3
│ └── ...
build_highlight_epub() functionbuild_lipsync_epub() functionAlignedChunk, WordTiming