A simple Python script that converts PDF files to audio files.
- Clone this repository.
- Install Python.
- Install Pip.
- Install the dependencies:
python3 -m pip install -r requirements.txt. - Put one or more text-based PDF files in the
inputfolder. - Run
python3 main.py. The defaulten-US-AriaNeuralvoice creates an MP3 inoutputwith the same name as each input PDF. - Existing files in
outputare 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-GuyNeuralFor offline conversion, use the operating system voice instead:
python3 main.py --offlineThe standard layout is:
input/
book-one.pdf
book-two.pdf
output/
Run this from the project folder:
python3 main.pyAll PDFs are read from input/ and processed in filename order. Each output keeps the input PDF's filename:
python3 main.py --voice en-US-EricNeuralFor 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.
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.
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.
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.mp3Replace the voice name and output filename to preview another voice. To list all available voices:
edge-tts --list-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 |
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.
Author: Scott Grivner
Email: scott.grivner@gmail.com
Website: linktr.ee/scottgriv
Reference: Main Branch