Skip to main content

Convert EPUB ebooks to OGG audiobooks with chapter markers

Project description

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

  1. Pip install
pip install epub2audio
  1. Clone this repository:
git clone https://github.com/clayrosenthal/epub2audio.git
cd epub2audio
  1. 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 training
  • af_heart (Female, Grade A) - Best overall quality
  • af_nicole (Female, Grade B-) - Good quality with extended training
  • am_fenrir (Male, Grade C+) - Best male voice option

British English

  • bf_emma (Female, Grade B-) - Best British female voice
  • bm_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)

  1. Invalid/corrupted EPUB file
  2. Invalid voice model selection
  3. File system errors (read/write permissions)
  4. Insufficient disk space

Non-Critical Errors (Warning and continue)

  1. Non-text elements in EPUB
  2. Unsupported metadata fields
  3. Minor formatting issues

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (mise run test)
  5. Format code (mise run format)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Guidelines

  1. Follow Google Python style guide
  2. Add tests for new features
  3. Update documentation as needed
  4. Keep commits focused and atomic

License

AGPL-3.0-or-later - See LICENSE file for details

Acknowledgments

  • Kokoro for text-to-speech processing
  • ebooklib for EPUB handling
  • mutagen for audio metadata
  • Voice training data contributors (see individual voice attributions)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epub2audio-0.3.1.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epub2audio-0.3.1-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file epub2audio-0.3.1.tar.gz.

File metadata

  • Download URL: epub2audio-0.3.1.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for epub2audio-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9a016efbffd94e8b8674ff988365137deebc88cf6da92b8647f745cea26c30bc
MD5 90082ca76cfe7c4d3eeaa3101f305ec1
BLAKE2b-256 c7d6be4cd10d2c91cc379e6e99a0688110c7b7c0310e2223871e2ef9a8eaefb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for epub2audio-0.3.1.tar.gz:

Publisher: pypi.yaml on clayrosenthal/epub2audio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epub2audio-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: epub2audio-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for epub2audio-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 480945d24f45b820ccd427f42c8b5545d118a4e2bd3a0ad1bd483ae0d3570e9f
MD5 81e94a33e9aa778ac58610e028d2d2b0
BLAKE2b-256 fdc7a2e4356949c54bac4ea6bf65f2ae929fa354e16a2e9b19f5d3d1510ad28a

See more details on using hashes here.

Provenance

The following attestation bundles were made for epub2audio-0.3.1-py3-none-any.whl:

Publisher: pypi.yaml on clayrosenthal/epub2audio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page