Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF to Audiobook Converter

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.

Installation

From GitHub

# 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.txt

System Dependencies

ffmpeg 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 PATH

Environment Setup

You'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

Usage

Command Line

# 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 --verbose

Python API

import 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
)

Command-Line Arguments

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

Requirements

  • Python 3.10+
  • ffmpeg (for audio format conversion)
  • Groq API key (free, for chapter detection)

About

A Simple python tool to convert PDF documents into audiobooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages