Skip to content

[Feature]: Support parsing/OCR of image-based chapter titles (common in Yen Press EPUBs) #80

Description

@starpause

What would you like to see?

I would like to request a feature where Alexandria can automatically parse text from images that serve as chapter headings/titles, using either a local OCR library (e.g., easyocr or tesseract) or a local Multimodal/Vision LLM (e.g., Qwen2-VL, Llama-3.2-Vision) if the user has one configured.

Steps to Reproduce / Test Case

I have generated a minimal, copyright-free sample EPUB that reproduces this exact structure:

sample_image_chapters.zip

EPUB Markup Structure

In this sample, the chapter files (chapter1.xhtml, chapter2.xhtml) contain:

<div class="title-container">
  <!-- The chapter title is represented solely as an image -->
  <img class="title-image" src="images/chapter1-title.png" alt="Chapter Title Image" />
</div>

The actual text rendered in the image is:

  • For Chapter 1: "Chapter I: The Awoken Princess"
  • For Chapter 2: "Chapter II: The Crimson Nocturne"

Currently, Alexandria imports this chapter structure but does not extract the text from the images, meaning the generated script does not contain the actual chapter names.

Proposed Solution

  1. Detection: During EPUB parsing, identify blocks or headings that contain an <img> element but no accompanying text.
  2. Text Extraction (OCR/VLM):
    • Option A (Lightweight OCR): Use a Python OCR library like easyocr or pytesseract to extract text from the referenced image.
    • Option B (VLM integration): If the backend has access to a vision-enabled model, send the image to the model with a prompt like: "Extract the text from this chapter title image exactly as written."
  3. Replacement: Inject the extracted text back into the internal parsed representation of the chapter title before sending it to the script generation phase.

Use case

Many light novels and manga-adjacent ebooks (especially those published by Yen Press, e.g., The Vexations of a Shut-In Vampire Princess) use stylized images (PNG/JPEG) instead of text for chapter titles.

When Alexandria parses these EPUBs:

  1. The parser misses the chapter title text entirely since it only sees an <img> tag (often with blank or generic alt text like "image" or "Chapter Title Image").
  2. This leads to missing chapter boundaries or generic labels in the generated script and the final chaptered audio output (e.g., M4B files).
  3. The LLM script generator is deprived of the chapter name context, which can affect the flow of script generation.

Publisher with this pattern: Yen Press, J-Novel Club (on certain titles), Kadokawa.

Alternatives considered

Before script generation I could pre-process the epub files myself to strip out chapter title images and replace them with text.

After script generation I could manually search for the first text in each chapter and insert new lines that include the chapter titles, for example by copy pasting from the TOC to each appropriate chapter title placement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions