Skip to main content

epub2m4b

CI

Chinese EPUB → chaptered M4B audiobook, as a single resumable CLI.

  • Chaptering: nav → nav+hybrid → outline → spine, with a vetoer that rejects implausible cuts and records why (see epub2m4b inspect --json).
  • Resumable: every segment is cached by sha256(text + synth_fingerprint). Interrupt with Ctrl-C / SIGKILL and rerun — finished segments are never redone.
  • Switch voices for free: switching back to a previous voice costs zero synthesis.
  • Chapter-accurate timeline: START/END computed from integer sample counts, verified against ffprobe within 150 ms.
  • Graceful degradation: DRM/image-only books exit 3; silent loudnorm measurement degrades to "loudnorm off + warning"; per-segment failures exit 2 with --allow-incomplete packaging what finished.

Install

python3 -m pip install epub2m4b            # core (fake + openai_compat TTS)
python3 -m pip install 'epub2m4b[kokoro]'  # + local Kokoro 0.9.4 engine
ffmpeg -version                            # ffmpeg + ffprobe are required

Use

epub2m4b doctor                      # check environment (never touches the DB)
epub2m4b inspect book.epub           # show chaptering strategy and segment counts
epub2m4b inspect book.epub --json    # machine-readable version
epub2m4b voices                      # list Kokoro voices (no model download)
epub2m4b voices --lang z             # only Mandarin voices
epub2m4b run book.epub --tts kokoro --voice zf_xiaobei -o book.m4b
epub2m4b status                      # library overview
epub2m4b status book.epub            # one book, including failed segments

Options on run: --voice, --rate, --jobs, --max-retries, --endpoint (for openai_compat), --bitrate, --no-loudnorm, --no-speak-titles, --include-front-matter, --allow-incomplete.

Exit codes: 0 success · 1 general error · 2 failed/incomplete segments · 3 unusable input · 4 TTS unavailable · 5 insufficient disk · 130 interrupted.

State

  • SOUNDBOOK_HOME (default ~/.local/share/soundbook): state.sqlite, locks/, work/.
  • SOUNDBOOK_CACHE_DIR (default ~/.cache/soundbook/audio): per-segment FLAC files, content-addressed.

TTS backends

--tts what it does
fake Deterministic silence, for tests/CI (loudnorm auto-disabled)
kokoro Local Kokoro 82M, default voice zf_xiaobei, lang_code inferred from the voice id (SOUNDBOOK_KOKORO_VOICE, SOUNDBOOK_KOKORO_LANG override)
openai_compat Any OpenAI-compatible /v1/audio/speech endpoint (CosyVoice, …). Env: SOUNDBOOK_TTS_URL, SOUNDBOOK_TTS_MODEL, SOUNDBOOK_TTS_VOICE

A failed segment is retried on the next run — failure is not sticky.

Kokoro notes: kokoro==0.9.4 requires Python < 3.13 (use the Docker image, which is 3.12, if your system Python is newer). Model weights come from Hugging Face on first run; behind a firewall set HF_ENDPOINT=https://hf-mirror.com and HF_HUB_DISABLE_XET=1 (the Xet CDN is not served by the mirror).

Docker

docker build -t epub2m4b .
docker run --rm -v "$PWD:/data" epub2m4b inspect book.epub
docker run --rm -v "$PWD:/data" epub2m4b run book.epub --tts fake -o book.m4b

The default image ships the core backends only. For the local Kokoro engine use Dockerfile.kokoro (Python 3.12, installs .[kokoro]; validated end to end, see docs/benchmarks.md Spike 2):

docker build -f Dockerfile.kokoro -t epub2m4b-kokoro .
docker run --rm -v "$PWD:/data" -e HF_ENDPOINT=https://hf-mirror.com -e HF_HUB_DISABLE_XET=1 \
  epub2m4b-kokoro run book.epub --tts kokoro -o book.m4b

The HF_* variables are only needed behind a firewall. The Kokoro image is large (about 10.5 GB with torch).

Two practical notes:

  • If pypi.org is unreachable from your Docker network, pass a mirror: docker build -t epub2m4b --build-arg PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple .
  • The container runs as root, so files it writes into a bind-mounted /data (the M4B, the cache, the SQLite state) are root-owned on the host. Use a named volume, or --user "$(id -u):$(id -g)" together with -e SOUNDBOOK_HOME=/tmp/state -e SOUNDBOOK_CACHE_DIR=/tmp/cache.

Development

python3 -m venv .venv && . .venv/bin/activate
python3 -m pip install -e ".[dev]"
pytest                    # unit + e2e (real ffmpeg, --tts fake)
pytest -m e2e             # only end-to-end
SOUNDBOOK_CORPUS=/path/to/epubs pytest -m corpus -s  # optional local real-book evaluation

Docs: docs/adr.md (decision records), docs/limitations.md, docs/benchmarks.md, docs/corpus.md (local annotation), docs/compat.md (sample/player matrix), docs/compare.md, docs/licenses.md.

Apache-2.0. No text, model weights or corpora are redistributed with this project. You are responsible for the legality of the EPUBs you convert. The optional Release-only public-domain sample is documented in docs/compat.md; it is not included in the repository or pip package.

Metadata

Release files for epub2m4b 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for epub2m4b 0.1.2
File Size Uploaded Provenance Actions
epub2m4b-0.1.2.tar.gz 46.1 kB With provenance Details for epub2m4b-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for epub2m4b 0.1.2
File Interpreter ABI Platform Actions
epub2m4b-0.1.2-py3-none-any.whl Python 3 none any Details for epub2m4b-0.1.2-py3-none-any.whl

Total release size: 103.2 kB

Release files / epub2m4b-0.1.2.tar.gz

Download URL epub2m4b-0.1.2.tar.gz
Size 46.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8738d454fa8f0c4429e0e95e4d3b386a528d1a04f6f0e61e75dc0061825135c1
BLAKE2b-256 checksum
How to use checksums
dfbc9c9e7bd4b4a9d6c1e9df406b9b647b9549401c3e385d0ac145596e55344b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / epub2m4b-0.1.2-py3-none-any.whl

Download URL epub2m4b-0.1.2-py3-none-any.whl
Size 57.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2880af52c0cfa89c68cd04383970aa7a33404606beb114d35ff5c13aa73b6519
BLAKE2b-256 checksum
How to use checksums
4af7ff381eb44df4828450cdb2d54c4f7abfb225400599bfbdc572ee8a545cf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for epub2m4b 0.1.2

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for epub2m4b-0.1.2.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 Nov 22, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page