A Python-based command-line tool that takes an EPUB or PDF document and converts it into a high-quality MP3 audiobook using native macOS text-to-speech capabilities.
- Multi-format Support: Extracts text flawlessly from both
.epub(chapter-by-chapter) and.pdf(sentence-by-sentence) files. - 100% Offline & Fast: Utilizes the built-in macOS
saycommand for high-quality, offline text-to-speech generation. No API keys or internet connection required. - Efficient Audio Merging: Automates the
ffmpegconcat demuxer to losslessly and efficiently stitch hundreds of audio chunks into a single, seamless.mp3file, without blowing up your system's memory. - Customizable Voices: Pick any installed macOS system voice (e.g., Alex, Samantha, Daniel) to read your books.
- macOS (Required for the native
sayTTS command). - Python 3.9+
(Note: ffmpeg is required to merge the audio files, but this script will automatically download a static binary into your virtual environment if one isn't natively installed via Homebrew!)
- Clone or download the repository.
- Create and activate a Python virtual environment:
python3 -m venv venv source venv/bin/activate - Install the required dependencies:
pip install EbookLib==0.18 beautifulsoup4==4.12.3 PyMuPDF==1.23.21 tqdm==4.66.2 click==8.1.7
Simply run main.py against your document:
# Basic usage (defaults to the "Alex" voice)
python main.py my_book.epub --output my_audiobook.mp3
# Use a specific macOS voice (e.g., Samantha)
python main.py my_document.pdf -v Samantha --output my_audiobook.mp3input_file: The path to the.epubor.pdffile you want to convert.--output/-o: Output audiobook file path (default:audiobook.mp3).--voice/-v: The macOS system voice to use (default:Alex).
extractor.py: Parses the files into clean, readable text chunks usingebooklib,beautifulsoup4, andPyMuPDF.tts_engine.py: Converts the text chunks into audio files asynchronously using macOSsay.compiler.py: Merges the generated audio files into the final audiobook usingffmpeg.main.py: The CLI application tying everything together with beautiful progress tracking viaclickandtqdm.