Skip to content

Conversation

@darktasevski
Copy link

This PR adds TTS (Text-to-Speech) functionality for PDF publications by integrating PDFKit-based text extraction capabilities.

Changes:

  • Add PDFResourceContentIterator for extracting text content from PDFs

    • Intelligent paragraph detection using multiple strategies
    • Precise locator positioning with page and paragraph indices
    • Platform-specific implementation using PDFKit (iOS, macOS, Catalyst)
  • Update PDFParser to register ContentService with PDF text iterator

    • Enables automatic TTS support for PDFs with extractable text
    • Maintains backward compatibility with existing code

The implementation is modular and follows the existing ContentIterator pattern used for EPUB publications. I'm using this approach in my app, and it works without any issues (at least, none that I'm aware of).

CleanShot.2025-11-09.at.11.29.58.mp4

This commit adds TTS (Text-to-Speech) functionality for PDF publications by integrating PDFKit-based text extraction capabilities.

Changes:
- Add PDFResourceContentIterator for extracting text content from PDFs
  - Intelligent paragraph detection using multiple strategies
  - Precise locator positioning with page and paragraph indices
  - Platform-specific implementation using PDFKit (iOS, macOS, Catalyst)

- Update PDFParser to register ContentService with PDF text iterator
  - Enables automatic TTS support for PDFs with extractable text
  - Maintains backward compatibility with existing code

The implementation is modular and follows the existing ContentIterator pattern used for EPUB publications, ensuring consistency across the toolkit.
@mickael-menu
Copy link
Member

Hi @darktasevski, thank you for contributing to the toolkit!

This looks like a valuable addition. However, given the complexity, it would be best to split this into two separate PRs:

  • PDF decorations
  • PDF content iterator

Would you mind starting with a new PR just for the PDF decorations?

Regarding the code, I have a few initial questions:

  • Locator Object: We generally avoid adding custom properties to the ⁠Locator object to maintain interoperability with other platforms. Could you clarify the specific purpose of the paragraph index here?
  • TTS Prosody: In the demo video, the TTS engine appears to read line-by-line rather than by sentence or paragraph. This results in broken prosody and interrupted sentences. Since smooth playback is a priority for us, have you considered an approach to handle sentence-level segmentation?

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