Skip to content

Repository files navigation


Python Badge
GitHub Badge Email Badge BuyMeACoffee Badge
Bronze


Python PDF File to Audio File

A simple Python script that converts PDF files to audio files.


Table of Contents

Getting Started

  1. Clone this repository.
  2. Install Python.
  3. Install Pip.
  4. Install the dependencies: python3 -m pip install -r requirements.txt.
  5. Put one or more text-based PDF files in the input folder.
  6. Run python3 main.py. The default en-US-AriaNeural voice creates an MP3 in output with the same name as each input PDF.
  7. Existing files in output are overwritten.

The input must be a text-based PDF. If conversion reports that no text could be extracted, open the PDF and export or print it to a new PDF first. Scanned PDFs require OCR before they can be converted.

To use a different voice for all PDFs, use:

python3 main.py --voice en-US-GuyNeural

For offline conversion, use the operating system voice instead:

python3 main.py --offline

Batch Conversion

The standard layout is:

input/
    book-one.pdf
    book-two.pdf
output/

Run this from the project folder:

python3 main.py

All PDFs are read from input/ and processed in filename order. Each output keeps the input PDF's filename:

python3 main.py --voice en-US-EricNeural

For example, input/book-one.pdf becomes output/book-one.mp3. Temporary speech chunks (for larger PDF files) are stored in output/audio_processing/ while the script runs, then that folder is deleted automatically.

After that, the final MP3 gets placed in the output/ folder and the temporary files are removed.

Pronunciation Rules

Custom pronunciations are stored in pronunciation.txt, using one replacement per line:

# API=A P I

This makes the voice read API as “A P I” vs. "A Pie". Add more rules in the same format when a name, acronym, or technical term needs a custom pronunciation.

Text Cleanup Rules

Header, footer, and table-of-contents cleanup rules are stored in text_cleanup.txt. Edit that file when a PDF uses different report headers, page numbers, or contents labels; the Python script loads those rules before extracting the audiobook text.

Preview Voices

Generate and play a short preview on macOS with:

edge-tts --voice en-US-GuyNeural --text "This is a preview of the audiobook voice." --write-media preview-guy.mp3
open preview-guy.mp3

Replace the voice name and output filename to preview another voice. To list all available voices:

edge-tts --list-voices

Popular Voices

Voice Style
en-US-GuyNeural American male, clear and natural
en-US-ChristopherNeural American male, warm and steady
en-US-EricNeural American male, deeper tone
en-US-RogerNeural American male, mature tone
en-GB-RyanNeural British male, conversational
en-GB-ThomasNeural British male, deeper tone
en-AU-WilliamNeural Australian male
en-IE-ConnorNeural Irish male
en-IN-PrabhatNeural Indian English male
en-US-JennyNeural American female, clear and friendly
en-US-AriaNeural American female, expressive and natural
en-US-SaraNeural American female, warm and conversational
en-GB-SoniaNeural British female, polished and clear
en-GB-LibbyNeural British female, bright and conversational
en-AU-NatashaNeural Australian female
en-IE-EmilyNeural Irish English female
en-IN-NeerjaNeural Indian English female

Resources

License

This project is released under the terms of The Unlicense, which allows you to use, modify, and distribute the code as you see fit.

  • The Unlicense removes traditional copyright restrictions, giving you the freedom to use the code in any way you choose.
  • For more details, see the LICENSE file in this repository.

Credits

Author: Scott Grivner
Email: scott.grivner@gmail.com
Website: linktr.ee/scottgriv
Reference: Main Branch


About

Convert pdf files to audio files (text to voice).

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages