A project to convert PDFs into audiobooks using text-to-speech technology.
- CPU: Tested on 64-bit AMD64 CPU with 16GB RAM
- Python: Version 3.12.1
Visit PyTorch official website for installation instructions.
This project uses the Kokoro-82M TTS model from Hugging Face. Kokoro is an open-weight TTS model with 82 million parameters that delivers high-quality audio while being lightweight and cost-efficient.
Before running the TTS script, you need to authenticate with Hugging Face:
python3
>>> from huggingface_hub import login
>>> login()
# Enter your Hugging Face token when promptedTo stitch together the generated WAV files, install FFmpeg.
Create a JSON file that defines the sections of your PDF with their corresponding page ranges. The file should follow this example format:
{
"Prologue" : {
"start" : 6,
"end" : 8
},
"Chapter 1" : {
"start" : 11,
"end" : 56
},
"Chapter 2" : {
"start" : 58,
"end" : 148
},
"Chapter 3" : {
"start" : 150,
"end" : 185
},
"Chapter 4" : {
"start" : 187,
"end" : 255
},
"Chapter 5" : {
"start" : 257,
"end" : 353
}
}Each key represents a chapter or section name, with start and end values indicating the page numbers for that section.
Run the extract text script with your PDF and index file:
python3 extract_text.py --pdf <path to PDF file> --index <path to page index json>Run the TTS conversion:
python3 tts.py