EPUB to Audiobook Converter
A command-line tool and library that converts EPUB ebooks to OGG audiobooks with chapter markers, using local text-to-speech processing with Kokoro.
Features
- Converts EPUB 3.0 files to OGG audiobooks
- Local text-to-speech processing using Kokoro
- Support for 9 languages with multiple voices:
- 🇺🇸 American English (11F, 9M voices)
- 🇬🇧 British English (4F, 4M voices)
- 🇯🇵 Japanese (4F, 1M voices)
- 🇨🇳 Mandarin Chinese (4F, 4M voices)
- 🇪🇸 Spanish (1F, 2M voices)
- 🇫🇷 French (1F voice)
- 🇮🇳 Hindi (2F, 2M voices)
- 🇮🇹 Italian (1F, 1M voices)
- 🇧🇷 Brazilian Portuguese (1F, 2M voices)
- Chapter markers in output files
- Configurable voice selection and speech rate
- Progress reporting with optional quiet mode
- Metadata preservation from EPUB to audio file
Requirements
- Python 3.10 or higher
- Dependencies listed in
pyproject.toml
Installation
- Pip install
pip install epub2audio
- Clone this repository:
git clone https://github.com/clayrosenthal/epub2audio.git
cd epub2audio
- Install dev setup using mise (recommended):
mise install
Or manually with a virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install -e .
Usage
Basic Usage
Convert an EPUB file to an audiobook with default settings:
epub2audio input.epub
The audiobook will be saved as Book_Title.ogg, but can be set with --output.
Voice Selection
The tool supports multiple voices across different languages. Here are some notable voices:
American English
af_bella(Female, Grade A-) - High quality with extended trainingaf_heart(Female, Grade A) - Best overall qualityaf_nicole(Female, Grade B-) - Good quality with extended trainingam_fenrir(Male, Grade C+) - Best male voice option
British English
bf_emma(Female, Grade B-) - Best British female voicebm_fable(Male, Grade C) - Best British male voice
Other Languages
ff_siwis(French Female, Grade B-)jf_alpha(Japanese Female, Grade C+)if_sara(Italian Female, Grade C)hf_alpha(Hindi Female, Grade C)
To use a specific voice:
epub2audio input.epub --voice af_bella
Advanced Options
epub2audio input.epub \
--output output.ogg \
--voice af_bella \
--speech-rate 1.0 \
--quiet
Command Line Options
input.epub: Path to input EPUB file--output,-o: Path of output audiobook file, defaults to title of the ebook.--voice,-v: Name of the voice to use (default: af_heart)--speech-rate,-r: Speech rate multiplier (default: 1.0)--quiet,-q: Suppress progress reporting--verbose,-v: Output more verbose logs--cache,-c: Cache generated audio files for reuse--max-chapters,-m: Max number of chapters to generate, or -1 for unlimited--format,-f: Output container format
Voice Quality Grades
Voices are graded based on quality and training data:
- A: Exceptional quality, extensive training
- B: Good quality, suitable for most uses
- C: Average quality, may have minor issues
- D: Basic quality, may have noticeable issues
- F: Limited quality, recommended only if necessary
Modifiers (+/-) indicate slight variations within each grade.
Development
Project Structure
src/
├── __init__.py
├── epub_processor.py # EPUB parsing and text extraction
├── audio_converter.py # TTS conversion using Kokoro
├── audio_handler.py # OGG creation, chapter markers, metadata
├── epub2audio.py # Main class, command line interface
├── voices.py # Voice definitions and management
├── helpers.py # Utility functions
└── config.py # Configuration settings
Running Tests
Using mise:
# Run all tests
mise run test
# Run integration tests
mise run test-integration
# Run with coverage
mise run test-coverage
Or manually:
# Run all tests
pytest
# Run integration tests
pytest --run-integration
# Run with coverage
pytest --cov=src tests/
Code Quality
The project uses:
- Ruff for formatting and linting
- MyPy for type checking
- Pytest for testing
To format and lint code:
mise run format # Format code
mise run lint # Check code
mise run fix # Auto-fix issues
Error Handling
Critical Errors (Exit with error code)
- Invalid/corrupted EPUB file
- Invalid voice model selection
- File system errors (read/write permissions)
- Insufficient disk space
Non-Critical Errors (Warning and continue)
- Non-text elements in EPUB
- Unsupported metadata fields
- Minor formatting issues
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
mise run test) - Format code (
mise run format) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
TO-DO:
- Add support for epub by link
- Add support for taking in multiple epubs on the command kine
- Add a webserver so you could host this
- Add support for more audio output formats
- Add support for images and vector graphics
- Either their alt text, or generate it with AI
- Better integration tests
- Add support for ONNX runtime
- Add support for other AI models
Development Guidelines
- Follow Google Python style guide
- Add tests for new features
- Update documentation as needed
- Keep commits focused and atomic
License
AGPL-3.0-or-later - See LICENSE file for details
Acknowledgments
- Kokoro for text-to-speech processing
- Huggingface for model weights
- ebooklib for EPUB handling
- mutagen for audio metadata
- Voice training data contributors (see individual voice attributions)
Metadata
Release files for epub2audio 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| epub2audio-0.5.0.tar.gz | 1.4 MB | With provenance | Details for epub2audio-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| epub2audio-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for epub2audio-0.5.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / epub2audio-0.5.0.tar.gz
| Download URL | epub2audio-0.5.0.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b8ed027b06d8035667b08f69da144ad1a2bd01e1c450602d6d9ba9b204086d8
|
|
BLAKE2b-256 checksum How to use checksums |
32b624433a9cd44feeb09a95fdf5836f87ef7f772298a63dbc48594b85d2f7ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 20, 2025.
Transparency logRelease files / epub2audio-0.5.0-py3-none-any.whl
| Download URL | epub2audio-0.5.0-py3-none-any.whl |
|---|---|
| Size | 38.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cea54de63a63a419e901faa940ccb9bf4b2cf2e231113f1400a0f5e52cfa395d
|
|
BLAKE2b-256 checksum How to use checksums |
9cad164119056f5f44e638a76fdb76c714660ae28d5060a43e53b4efa56cfa0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 20, 2025.
Transparency logSecurity for epub2audio 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for epub2audio-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 20, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.