E2E6 GitHub - mgmanzella/PdfToAudiobook: A simple way of converting a pdf to an audiobook · GitHub
[go: up one dir, main page]

Skip to content

About

A simple way of converting a pdf to an audiobook

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Simple PDF to Audiobook

Note: This is a fork of Simple PDF to Audiobook. Original project by Estikno.

This project converts PDF books into AI-narrated audiobooks using Coqui-TTS (fork), PyMuPDF and jenkspy. Everything is done locally so there is no need for api keys, credits, etc.

What's New in This Fork

  • Multiple TTS engines - Support for three different text-to-speech engines (Coqui-TTS, Chatterbox-TTS, Kokoro-TTS)
  • Dependency management - Added pyproject.toml with uv support
  • Local AI development setup - Configured with LM Studio and Qwen3 Coder Next for local code assistance via opencode.json
  • Sequential audio validation - join_audios.py now checks that all audio blocks are present and warns if any are missing from the sequence

Using uv

This project includes a pyproject.toml for dependency management with uv:

To install required dependencies:

uv sync

To run the scripts below if you're using uv:

uv run python extract_text.py
uv run python classify.py
uv run python tts_chatterbox.py # or whatever tts engine you want to use
uv run python join_audios.py

How to use it

  1. Extract text from the PDF
    python extract_text.py
  • The script opens book.pdf (the PDF must have this name).
  • It generates a file vision_output.json containing the text blocks and their font sizes.
  1. Classify text blocks

    python classify.py
    • Uses Jenks natural breaks to classify text as:
      • header (titles),
      • body (main content),
      • caption (subtitles),
      • other (things to skip, e.g. page numbers).
    • Saves the result as classified_text.json.
  2. Generate audio with Coqui-TTS

    python tts.py
    • Converts each block from classified_text.json into audio.
    • Produces one WAV file per block inside the temp/ folder.

    👉 If you stop synthesis halfway through, it's fine:

    all previously generated blocks remain in temp/, and you can continue from there.

  3. Join the audio files

    python join_audios.py
    • Sorts audio blocks by number and validates they're sequential.
    • Alerts if any blocks are missing from the sequence.
    • Concatenates all .wav files from temp/ into a single final audiobook.mp3 using FFmpeg.

Dependencies

You'll need these libraries and tools installed. If you're not using uv the pip commands are below for the python dependencies.

Alternative TTS dependencies

  • Chatterbox-TTS: chatterbox-tts, peft, perth
  • Kokoro-TTS: kokoro-tts (downloads model files automatically: kokoro-v1.0.onnx, voices-v1.0.bin)

AI Model Setup

This project uses a local LLM via LM Studio with opencode.json configuration:

  • Model: Qwen3 Coder Next (local)
  • Endpoint: http://127.0.0.1:1234/v1 (LM Studio default)

Start LM Studio, load your model, and enable the OpenAI-compatible server to use opencode features.


Notes

  • The input PDF must be named book.pdf and placed in the project folder.
  • For now the pipeline is very basic and experimental. If you don't mind tweaking some code, you can adjust things like:
    • The page ranges to process.
    • The thresholds for text classification.
    • The voice or language in Coqui-TTS.
  • If the book is long, the audio is split into small blocks (temp/block_X.wav) so you don't lose progress. You can edit the TTS scripts to skip blocks you have already processed (see START_BLOCK in tts_chatterbox.py).
  • The join_audios.py script now validates that all audio blocks are present sequentially and warns if any are missing.

TTS Options

This project includes three different TTS engines:

  • tts.py - Uses Coqui-TTS (default, multilingual)
  • tts_chatterbox.py - Uses Chatterbox-TTS for high-quality voice synthesis with audio conditioning. Find an AI narrator you prefer and provide a 30-second sample audio file (e.g., audio_sample.mp3) to mimic that specific voice style.
  • tts_kokoro.py - Uses Kokoro-TTS and supports different built in voice style options (lightweight, fast)

All scripts read from classified_text.json and output to temp/block_X.wav.


Files to ignore

The following files are added to .gitignore and should not be committed:

  • Audio files (audiobook.mp3, audio_sample.mp3, etc.)
  • TTS model files (kokoro-v1.0.onnx, voices-v1.0.bin)
  • TTS scripts (tts_chatterbox.py, tts_kokoro.py)
  • Backup/classified text files (classified_text_backup.json)

About

A simple way of converting a pdf to an audiobook

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0