A Python tool that converts PDF documents into high-quality audiobooks powered by Supertonic TTS and Groq. The tool automatically detects chapters, extracts text, and generates audio files.
I built this tool for my personal use. That said, if you find it useful, feel free to report issues, suggest improvements.
# Clone the repository
git clone https://github.com/Karthick47v2/pdf-to-audiobook.git
cd pdf-to-audiobook
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtffmpeg is required for audio format conversion:
# macOS
brew install ffmpeg
# Linux (Ubuntu/Debian)
sudo apt-get update && sudo apt-get install ffmpeg
# Windows
# Download from https://ffmpeg.org/download.html and add to PATHYou'll need a Groq API key for chapter heading detection. Get one free at console.groq.com.
# Create .env file in the project directory
echo "GROQ_API_KEY=your_api_key_here" > .env# Basic usage (outputs WAV format)
pdf-to-audiobook document.pdf
# Specify output file
pdf-to-audiobook document.pdf --output my_audiobook.wav
# Compress to M4A format (requires ffmpeg)
pdf-to-audiobook document.pdf --compress
# Compress with custom output name
pdf-to-audiobook document.pdf --output audiobook.m4a --compress
# Use a different voice --- Please see Supertonic TTS offical repo/page for available voices
pdf-to-audiobook document.pdf --voice M1
# Start from a specific page
pdf-to-audiobook document.pdf --start-page 5
# Disable chapter detection
pdf-to-audiobook document.pdf --no-chapters
# Enable verbose logging
pdf-to-audiobook document.pdf --verboseimport logging
from pdf_to_audiobook import PDFToAudiobookConverter, Settings, setup_logging
# Optional: Enable logging to see progress
setup_logging(level=logging.INFO)
# Basic usage
converter = PDFToAudiobookConverter()
success, tts_time, conv_time = converter.convert(input_pdf="document.pdf", output_path="output.wav")
# With custom settings
settings = Settings(
default_voice="M1",
audio_bitrate="320k"
)
converter = PDFToAudiobookConverter(voice="M1", settings=settings)
converter.convert(
input_pdf="document.pdf",
output_path="output.m4a",
start_page=5,
no_chapters=False,
compress=True
)| Argument | Short | Description | Default |
|---|---|---|---|
input_pdf |
Path to the input PDF file | (required) | |
--output |
-o |
Path to the output audio file | audiobook.wav |
--voice |
-v |
Voice style to use | F5 |
--compress |
-c |
Compress output to M4A format at 320kbps | False |
--start-page |
-s |
Page number to start from | 1 |
--no-chapters |
Disable chapter detection | False |
|
--verbose |
Enable verbose logging | False |
- Python 3.10+
- ffmpeg (for audio format conversion)
- Groq API key (free, for chapter detection)