This script converts a PDF document into MP3 audio files using Edge TTS and merges them into a smaller number of final audio files. Below is a step-by-step guide to use the script.
-
Python 3.6+
-
Install required Python packages:
pip install edge-tts pydub PyPDF2
-
Install ffmpeg for audio processing:
- On macOS (using Homebrew):
brew install ffmpeg
- On Ubuntu/Debian:
sudo apt install ffmpeg
- On Windows: Download from FFmpeg official website and add it to your PATH.
- On macOS (using Homebrew):
Run the script from the terminal using:
python3 book2mp3.py <path_to_pdf> [options]
<path_to_pdf>
: Path to the PDF file you want to convert.
-o
,--output
: Specify the output folder for MP3 files (default:output_mp3s
).-c
,--chunk-size
: Set the approximate number of characters per text chunk (default:6000
).-v
,--voice
: Choose the Edge TTS voice (default:en-US-JennyNeural
).
python3 book2mp3.py example.pdf
python3 book2mp3.py example.pdf -o custom_output -v en-GB-RyanNeural
- Intermediate MP3 Files: Saved as
part_001.mp3
,part_002.mp3
, etc., in the output folder. - Merged MP3 Files: Final merged files are saved as
final_part_001.mp3
,final_part_002.mp3
, etc.
- Ensure your PDF contains selectable text; scanned PDFs without OCR won't work.
- Adjust
CHUNK_SIZE
andPAUSE_DURATION
in the script if experiencing issues with large files or throttling. - Check Edge TTS voices for additional voice options.