epub2m4b 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. epub2m4b-0.1.0/LICENSE +202 -0
  2. epub2m4b-0.1.0/PKG-INFO +118 -0
  3. epub2m4b-0.1.0/README.md +96 -0
  4. epub2m4b-0.1.0/pyproject.toml +47 -0
  5. epub2m4b-0.1.0/setup.cfg +4 -0
  6. epub2m4b-0.1.0/src/epub2m4b.egg-info/PKG-INFO +118 -0
  7. epub2m4b-0.1.0/src/epub2m4b.egg-info/SOURCES.txt +43 -0
  8. epub2m4b-0.1.0/src/epub2m4b.egg-info/dependency_links.txt +1 -0
  9. epub2m4b-0.1.0/src/epub2m4b.egg-info/entry_points.txt +2 -0
  10. epub2m4b-0.1.0/src/epub2m4b.egg-info/requires.txt +12 -0
  11. epub2m4b-0.1.0/src/epub2m4b.egg-info/top_level.txt +1 -0
  12. epub2m4b-0.1.0/src/soundbook/__init__.py +11 -0
  13. epub2m4b-0.1.0/src/soundbook/__main__.py +6 -0
  14. epub2m4b-0.1.0/src/soundbook/assemble/__init__.py +1 -0
  15. epub2m4b-0.1.0/src/soundbook/assemble/concat.py +117 -0
  16. epub2m4b-0.1.0/src/soundbook/assemble/loudnorm.py +80 -0
  17. epub2m4b-0.1.0/src/soundbook/assemble/m4b.py +195 -0
  18. epub2m4b-0.1.0/src/soundbook/assemble/silence.py +29 -0
  19. epub2m4b-0.1.0/src/soundbook/cli.py +495 -0
  20. epub2m4b-0.1.0/src/soundbook/config.py +237 -0
  21. epub2m4b-0.1.0/src/soundbook/db.py +314 -0
  22. epub2m4b-0.1.0/src/soundbook/ingest/__init__.py +1 -0
  23. epub2m4b-0.1.0/src/soundbook/ingest/anchors.py +100 -0
  24. epub2m4b-0.1.0/src/soundbook/ingest/chaptering.py +352 -0
  25. epub2m4b-0.1.0/src/soundbook/ingest/classify.py +42 -0
  26. epub2m4b-0.1.0/src/soundbook/ingest/clean.py +136 -0
  27. epub2m4b-0.1.0/src/soundbook/ingest/loader.py +229 -0
  28. epub2m4b-0.1.0/src/soundbook/ingest/metrics.py +48 -0
  29. epub2m4b-0.1.0/src/soundbook/models.py +118 -0
  30. epub2m4b-0.1.0/src/soundbook/pipeline.py +335 -0
  31. epub2m4b-0.1.0/src/soundbook/py.typed +0 -0
  32. epub2m4b-0.1.0/src/soundbook/segment/__init__.py +1 -0
  33. epub2m4b-0.1.0/src/soundbook/segment/segmenter.py +147 -0
  34. epub2m4b-0.1.0/src/soundbook/tts/__init__.py +1 -0
  35. epub2m4b-0.1.0/src/soundbook/tts/base.py +48 -0
  36. epub2m4b-0.1.0/src/soundbook/tts/fake.py +38 -0
  37. epub2m4b-0.1.0/src/soundbook/tts/kokoro_local.py +62 -0
  38. epub2m4b-0.1.0/src/soundbook/tts/openai_compat.py +65 -0
  39. epub2m4b-0.1.0/src/soundbook/tts/voices.py +95 -0
  40. epub2m4b-0.1.0/src/soundbook/util/__init__.py +1 -0
  41. epub2m4b-0.1.0/src/soundbook/util/atomic.py +35 -0
  42. epub2m4b-0.1.0/src/soundbook/util/audio.py +117 -0
  43. epub2m4b-0.1.0/src/soundbook/util/disk.py +40 -0
  44. epub2m4b-0.1.0/src/soundbook/util/hashing.py +22 -0
  45. epub2m4b-0.1.0/src/soundbook/util/process.py +51 -0
epub2m4b-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: epub2m4b
3
+ Version: 0.1.0
4
+ Summary: Chinese EPUB → chaptered M4B audiobook generator (CLI)
5
+ Author: soundbook authors
6
+ License: Apache-2.0
7
+ Keywords: epub,m4b,audiobook,tts,chinese
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: epub-extended==0.2.3
12
+ Requires-Dist: lxml>=5
13
+ Requires-Dist: click>=8
14
+ Requires-Dist: filelock>=3
15
+ Provides-Extra: kokoro
16
+ Requires-Dist: kokoro==0.9.4; extra == "kokoro"
17
+ Requires-Dist: misaki[zh]==0.9.4; extra == "kokoro"
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == "dev"
20
+ Requires-Dist: soundfile; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # epub2m4b
24
+
25
+ [![CI](https://github.com/whoamiWo/book2sound/actions/workflows/ci.yml/badge.svg)](https://github.com/whoamiWo/book2sound/actions/workflows/ci.yml)
26
+
27
+ Chinese EPUB → chaptered **M4B** audiobook, as a single resumable CLI.
28
+
29
+ - **Chaptering**: nav → nav+hybrid → outline → spine, with a vetoer that rejects implausible cuts and records *why* (see `epub2m4b inspect --json`).
30
+ - **Resumable**: every segment is cached by `sha256(text + synth_fingerprint)`. Interrupt with Ctrl-C / SIGKILL and rerun — finished segments are never redone.
31
+ - **Switch voices for free**: switching back to a previous voice costs zero synthesis.
32
+ - **Chapter-accurate timeline**: START/END computed from integer sample counts, verified against ffprobe within 150 ms.
33
+ - **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.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ python3 -m pip install epub2m4b # core (fake + openai_compat TTS)
39
+ python3 -m pip install 'epub2m4b[kokoro]' # + local Kokoro 0.9.4 engine
40
+ ffmpeg -version # ffmpeg + ffprobe are required
41
+ ```
42
+
43
+ ## Use
44
+
45
+ ```bash
46
+ epub2m4b doctor # check environment (never touches the DB)
47
+ epub2m4b inspect book.epub # show chaptering strategy and segment counts
48
+ epub2m4b inspect book.epub --json # machine-readable version
49
+ epub2m4b voices # list Kokoro voices (no model download)
50
+ epub2m4b voices --lang z # only Mandarin voices
51
+ epub2m4b run book.epub --tts kokoro --voice zf_xiaobei -o book.m4b
52
+ epub2m4b status # library overview
53
+ epub2m4b status book.epub # one book, including failed segments
54
+ ```
55
+
56
+ Options on `run`: `--voice`, `--rate`, `--jobs`, `--max-retries`, `--endpoint` (for `openai_compat`), `--bitrate`, `--no-loudnorm`, `--no-speak-titles`, `--include-front-matter`, `--allow-incomplete`.
57
+
58
+ Exit codes: **0** success · **1** general error · **2** failed/incomplete segments · **3** unusable input · **4** TTS unavailable · **5** insufficient disk · **130** interrupted.
59
+
60
+ ## State
61
+
62
+ - `SOUNDBOOK_HOME` (default `~/.local/share/soundbook`): `state.sqlite`, `locks/`, `work/`.
63
+ - `SOUNDBOOK_CACHE_DIR` (default `~/.cache/soundbook/audio`): per-segment FLAC files, content-addressed.
64
+
65
+ ## TTS backends
66
+
67
+ | `--tts` | what it does |
68
+ | --- | --- |
69
+ | `fake` | Deterministic silence, for tests/CI (loudnorm auto-disabled) |
70
+ | `kokoro` | Local Kokoro 82M, default voice `zf_xiaobei`, `lang_code` inferred from the voice id (`SOUNDBOOK_KOKORO_VOICE`, `SOUNDBOOK_KOKORO_LANG` override) |
71
+ | `openai_compat` | Any OpenAI-compatible `/v1/audio/speech` endpoint (CosyVoice, …). Env: `SOUNDBOOK_TTS_URL`, `SOUNDBOOK_TTS_MODEL`, `SOUNDBOOK_TTS_VOICE` |
72
+
73
+ A failed segment is retried on the next `run` — failure is not sticky.
74
+
75
+ Kokoro notes: `kokoro==0.9.4` requires **Python < 3.13** (use the Docker image, which is
76
+ 3.12, if your system Python is newer). Model weights come from Hugging Face on first
77
+ run; behind a firewall set `HF_ENDPOINT=https://hf-mirror.com` and
78
+ `HF_HUB_DISABLE_XET=1` (the Xet CDN is not served by the mirror).
79
+
80
+ ## Docker
81
+
82
+ ```bash
83
+ docker build -t epub2m4b .
84
+ docker run --rm -v "$PWD:/data" epub2m4b inspect book.epub
85
+ docker run --rm -v "$PWD:/data" epub2m4b run book.epub --tts fake -o book.m4b
86
+ ```
87
+
88
+ The default image ships the core backends only. For the local Kokoro engine use `Dockerfile.kokoro` (Python 3.12, installs `.[kokoro]`; reconstructed recipe, see the comments at its top):
89
+
90
+ ```bash
91
+ docker build -f Dockerfile.kokoro -t epub2m4b-kokoro .
92
+ docker run --rm -v "$PWD:/data" -e HF_ENDPOINT=https://hf-mirror.com -e HF_HUB_DISABLE_XET=1 \
93
+ epub2m4b-kokoro run book.epub --tts kokoro -o book.m4b
94
+ ```
95
+
96
+ The `HF_*` variables are only needed behind a firewall. The Kokoro image is large (about 10.5 GB with torch).
97
+
98
+ Two practical notes:
99
+
100
+ - If `pypi.org` is unreachable from your Docker network, pass a mirror:
101
+ `docker build -t epub2m4b --build-arg PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple .`
102
+ - 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`.
103
+
104
+ ## Development
105
+
106
+ ```bash
107
+ python3 -m venv .venv && . .venv/bin/activate
108
+ python3 -m pip install -e ".[dev]"
109
+ pytest # unit + e2e (real ffmpeg, --tts fake)
110
+ pytest -m e2e # only end-to-end
111
+ pytest -m corpus # local real-book corpus (never in CI)
112
+ ```
113
+
114
+ Docs: [`docs/adr.md`](docs/adr.md) (decision records), [`docs/limitations.md`](docs/limitations.md), [`docs/benchmarks.md`](docs/benchmarks.md), [`docs/compare.md`](docs/compare.md), [`docs/licenses.md`](docs/licenses.md).
115
+
116
+ ## Legal
117
+
118
+ 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.
@@ -0,0 +1,96 @@
1
+ # epub2m4b
2
+
3
+ [![CI](https://github.com/whoamiWo/book2sound/actions/workflows/ci.yml/badge.svg)](https://github.com/whoamiWo/book2sound/actions/workflows/ci.yml)
4
+
5
+ Chinese EPUB → chaptered **M4B** audiobook, as a single resumable CLI.
6
+
7
+ - **Chaptering**: nav → nav+hybrid → outline → spine, with a vetoer that rejects implausible cuts and records *why* (see `epub2m4b inspect --json`).
8
+ - **Resumable**: every segment is cached by `sha256(text + synth_fingerprint)`. Interrupt with Ctrl-C / SIGKILL and rerun — finished segments are never redone.
9
+ - **Switch voices for free**: switching back to a previous voice costs zero synthesis.
10
+ - **Chapter-accurate timeline**: START/END computed from integer sample counts, verified against ffprobe within 150 ms.
11
+ - **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.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ python3 -m pip install epub2m4b # core (fake + openai_compat TTS)
17
+ python3 -m pip install 'epub2m4b[kokoro]' # + local Kokoro 0.9.4 engine
18
+ ffmpeg -version # ffmpeg + ffprobe are required
19
+ ```
20
+
21
+ ## Use
22
+
23
+ ```bash
24
+ epub2m4b doctor # check environment (never touches the DB)
25
+ epub2m4b inspect book.epub # show chaptering strategy and segment counts
26
+ epub2m4b inspect book.epub --json # machine-readable version
27
+ epub2m4b voices # list Kokoro voices (no model download)
28
+ epub2m4b voices --lang z # only Mandarin voices
29
+ epub2m4b run book.epub --tts kokoro --voice zf_xiaobei -o book.m4b
30
+ epub2m4b status # library overview
31
+ epub2m4b status book.epub # one book, including failed segments
32
+ ```
33
+
34
+ Options on `run`: `--voice`, `--rate`, `--jobs`, `--max-retries`, `--endpoint` (for `openai_compat`), `--bitrate`, `--no-loudnorm`, `--no-speak-titles`, `--include-front-matter`, `--allow-incomplete`.
35
+
36
+ Exit codes: **0** success · **1** general error · **2** failed/incomplete segments · **3** unusable input · **4** TTS unavailable · **5** insufficient disk · **130** interrupted.
37
+
38
+ ## State
39
+
40
+ - `SOUNDBOOK_HOME` (default `~/.local/share/soundbook`): `state.sqlite`, `locks/`, `work/`.
41
+ - `SOUNDBOOK_CACHE_DIR` (default `~/.cache/soundbook/audio`): per-segment FLAC files, content-addressed.
42
+
43
+ ## TTS backends
44
+
45
+ | `--tts` | what it does |
46
+ | --- | --- |
47
+ | `fake` | Deterministic silence, for tests/CI (loudnorm auto-disabled) |
48
+ | `kokoro` | Local Kokoro 82M, default voice `zf_xiaobei`, `lang_code` inferred from the voice id (`SOUNDBOOK_KOKORO_VOICE`, `SOUNDBOOK_KOKORO_LANG` override) |
49
+ | `openai_compat` | Any OpenAI-compatible `/v1/audio/speech` endpoint (CosyVoice, …). Env: `SOUNDBOOK_TTS_URL`, `SOUNDBOOK_TTS_MODEL`, `SOUNDBOOK_TTS_VOICE` |
50
+
51
+ A failed segment is retried on the next `run` — failure is not sticky.
52
+
53
+ Kokoro notes: `kokoro==0.9.4` requires **Python < 3.13** (use the Docker image, which is
54
+ 3.12, if your system Python is newer). Model weights come from Hugging Face on first
55
+ run; behind a firewall set `HF_ENDPOINT=https://hf-mirror.com` and
56
+ `HF_HUB_DISABLE_XET=1` (the Xet CDN is not served by the mirror).
57
+
58
+ ## Docker
59
+
60
+ ```bash
61
+ docker build -t epub2m4b .
62
+ docker run --rm -v "$PWD:/data" epub2m4b inspect book.epub
63
+ docker run --rm -v "$PWD:/data" epub2m4b run book.epub --tts fake -o book.m4b
64
+ ```
65
+
66
+ The default image ships the core backends only. For the local Kokoro engine use `Dockerfile.kokoro` (Python 3.12, installs `.[kokoro]`; reconstructed recipe, see the comments at its top):
67
+
68
+ ```bash
69
+ docker build -f Dockerfile.kokoro -t epub2m4b-kokoro .
70
+ docker run --rm -v "$PWD:/data" -e HF_ENDPOINT=https://hf-mirror.com -e HF_HUB_DISABLE_XET=1 \
71
+ epub2m4b-kokoro run book.epub --tts kokoro -o book.m4b
72
+ ```
73
+
74
+ The `HF_*` variables are only needed behind a firewall. The Kokoro image is large (about 10.5 GB with torch).
75
+
76
+ Two practical notes:
77
+
78
+ - If `pypi.org` is unreachable from your Docker network, pass a mirror:
79
+ `docker build -t epub2m4b --build-arg PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple .`
80
+ - 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`.
81
+
82
+ ## Development
83
+
84
+ ```bash
85
+ python3 -m venv .venv && . .venv/bin/activate
86
+ python3 -m pip install -e ".[dev]"
87
+ pytest # unit + e2e (real ffmpeg, --tts fake)
88
+ pytest -m e2e # only end-to-end
89
+ pytest -m corpus # local real-book corpus (never in CI)
90
+ ```
91
+
92
+ Docs: [`docs/adr.md`](docs/adr.md) (decision records), [`docs/limitations.md`](docs/limitations.md), [`docs/benchmarks.md`](docs/benchmarks.md), [`docs/compare.md`](docs/compare.md), [`docs/licenses.md`](docs/licenses.md).
93
+
94
+ ## Legal
95
+
96
+ 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.
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "epub2m4b"
7
+ version = "0.1.0"
8
+ description = "Chinese EPUB → chaptered M4B audiobook generator (CLI)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "soundbook authors" }]
13
+ keywords = ["epub", "m4b", "audiobook", "tts", "chinese"]
14
+ dependencies = [
15
+ "epub-extended==0.2.3",
16
+ "lxml>=5",
17
+ "click>=8",
18
+ "filelock>=3",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ kokoro = ["kokoro==0.9.4", "misaki[zh]==0.9.4"]
23
+ dev = ["pytest", "soundfile"]
24
+
25
+ [project.scripts]
26
+ epub2m4b = "soundbook.cli:main"
27
+
28
+ [tool.setuptools.packages.find]
29
+ where = ["src"]
30
+
31
+ [tool.pytest.ini_options]
32
+ testpaths = ["tests"]
33
+ addopts = "-q"
34
+ markers = [
35
+ "corpus: local real-book corpus evaluation (never runs in CI)",
36
+ "e2e: end-to-end pipeline tests (real ffmpeg, --tts fake)",
37
+ ]
38
+
39
+ [tool.ruff]
40
+ line-length = 100
41
+ target-version = "py310"
42
+
43
+ [tool.ruff.lint]
44
+ select = ["E", "F", "I", "W", "UP", "B"]
45
+
46
+ [tool.setuptools.package-data]
47
+ soundbook = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: epub2m4b
3
+ Version: 0.1.0
4
+ Summary: Chinese EPUB → chaptered M4B audiobook generator (CLI)
5
+ Author: soundbook authors
6
+ License: Apache-2.0
7
+ Keywords: epub,m4b,audiobook,tts,chinese
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: epub-extended==0.2.3
12
+ Requires-Dist: lxml>=5
13
+ Requires-Dist: click>=8
14
+ Requires-Dist: filelock>=3
15
+ Provides-Extra: kokoro
16
+ Requires-Dist: kokoro==0.9.4; extra == "kokoro"
17
+ Requires-Dist: misaki[zh]==0.9.4; extra == "kokoro"
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == "dev"
20
+ Requires-Dist: soundfile; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # epub2m4b
24
+
25
+ [![CI](https://github.com/whoamiWo/book2sound/actions/workflows/ci.yml/badge.svg)](https://github.com/whoamiWo/book2sound/actions/workflows/ci.yml)
26
+
27
+ Chinese EPUB → chaptered **M4B** audiobook, as a single resumable CLI.
28
+
29
+ - **Chaptering**: nav → nav+hybrid → outline → spine, with a vetoer that rejects implausible cuts and records *why* (see `epub2m4b inspect --json`).
30
+ - **Resumable**: every segment is cached by `sha256(text + synth_fingerprint)`. Interrupt with Ctrl-C / SIGKILL and rerun — finished segments are never redone.
31
+ - **Switch voices for free**: switching back to a previous voice costs zero synthesis.
32
+ - **Chapter-accurate timeline**: START/END computed from integer sample counts, verified against ffprobe within 150 ms.
33
+ - **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.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ python3 -m pip install epub2m4b # core (fake + openai_compat TTS)
39
+ python3 -m pip install 'epub2m4b[kokoro]' # + local Kokoro 0.9.4 engine
40
+ ffmpeg -version # ffmpeg + ffprobe are required
41
+ ```
42
+
43
+ ## Use
44
+
45
+ ```bash
46
+ epub2m4b doctor # check environment (never touches the DB)
47
+ epub2m4b inspect book.epub # show chaptering strategy and segment counts
48
+ epub2m4b inspect book.epub --json # machine-readable version
49
+ epub2m4b voices # list Kokoro voices (no model download)
50
+ epub2m4b voices --lang z # only Mandarin voices
51
+ epub2m4b run book.epub --tts kokoro --voice zf_xiaobei -o book.m4b
52
+ epub2m4b status # library overview
53
+ epub2m4b status book.epub # one book, including failed segments
54
+ ```
55
+
56
+ Options on `run`: `--voice`, `--rate`, `--jobs`, `--max-retries`, `--endpoint` (for `openai_compat`), `--bitrate`, `--no-loudnorm`, `--no-speak-titles`, `--include-front-matter`, `--allow-incomplete`.
57
+
58
+ Exit codes: **0** success · **1** general error · **2** failed/incomplete segments · **3** unusable input · **4** TTS unavailable · **5** insufficient disk · **130** interrupted.
59
+
60
+ ## State
61
+
62
+ - `SOUNDBOOK_HOME` (default `~/.local/share/soundbook`): `state.sqlite`, `locks/`, `work/`.
63
+ - `SOUNDBOOK_CACHE_DIR` (default `~/.cache/soundbook/audio`): per-segment FLAC files, content-addressed.
64
+
65
+ ## TTS backends
66
+
67
+ | `--tts` | what it does |
68
+ | --- | --- |
69
+ | `fake` | Deterministic silence, for tests/CI (loudnorm auto-disabled) |
70
+ | `kokoro` | Local Kokoro 82M, default voice `zf_xiaobei`, `lang_code` inferred from the voice id (`SOUNDBOOK_KOKORO_VOICE`, `SOUNDBOOK_KOKORO_LANG` override) |
71
+ | `openai_compat` | Any OpenAI-compatible `/v1/audio/speech` endpoint (CosyVoice, …). Env: `SOUNDBOOK_TTS_URL`, `SOUNDBOOK_TTS_MODEL`, `SOUNDBOOK_TTS_VOICE` |
72
+
73
+ A failed segment is retried on the next `run` — failure is not sticky.
74
+
75
+ Kokoro notes: `kokoro==0.9.4` requires **Python < 3.13** (use the Docker image, which is
76
+ 3.12, if your system Python is newer). Model weights come from Hugging Face on first
77
+ run; behind a firewall set `HF_ENDPOINT=https://hf-mirror.com` and
78
+ `HF_HUB_DISABLE_XET=1` (the Xet CDN is not served by the mirror).
79
+
80
+ ## Docker
81
+
82
+ ```bash
83
+ docker build -t epub2m4b .
84
+ docker run --rm -v "$PWD:/data" epub2m4b inspect book.epub
85
+ docker run --rm -v "$PWD:/data" epub2m4b run book.epub --tts fake -o book.m4b
86
+ ```
87
+
88
+ The default image ships the core backends only. For the local Kokoro engine use `Dockerfile.kokoro` (Python 3.12, installs `.[kokoro]`; reconstructed recipe, see the comments at its top):
89
+
90
+ ```bash
91
+ docker build -f Dockerfile.kokoro -t epub2m4b-kokoro .
92
+ docker run --rm -v "$PWD:/data" -e HF_ENDPOINT=https://hf-mirror.com -e HF_HUB_DISABLE_XET=1 \
93
+ epub2m4b-kokoro run book.epub --tts kokoro -o book.m4b
94
+ ```
95
+
96
+ The `HF_*` variables are only needed behind a firewall. The Kokoro image is large (about 10.5 GB with torch).
97
+
98
+ Two practical notes:
99
+
100
+ - If `pypi.org` is unreachable from your Docker network, pass a mirror:
101
+ `docker build -t epub2m4b --build-arg PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple .`
102
+ - 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`.
103
+
104
+ ## Development
105
+
106
+ ```bash
107
+ python3 -m venv .venv && . .venv/bin/activate
108
+ python3 -m pip install -e ".[dev]"
109
+ pytest # unit + e2e (real ffmpeg, --tts fake)
110
+ pytest -m e2e # only end-to-end
111
+ pytest -m corpus # local real-book corpus (never in CI)
112
+ ```
113
+
114
+ Docs: [`docs/adr.md`](docs/adr.md) (decision records), [`docs/limitations.md`](docs/limitations.md), [`docs/benchmarks.md`](docs/benchmarks.md), [`docs/compare.md`](docs/compare.md), [`docs/licenses.md`](docs/licenses.md).
115
+
116
+ ## Legal
117
+
118
+ 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.
@@ -0,0 +1,43 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/epub2m4b.egg-info/PKG-INFO
5
+ src/epub2m4b.egg-info/SOURCES.txt
6
+ src/epub2m4b.egg-info/dependency_links.txt
7
+ src/epub2m4b.egg-info/entry_points.txt
8
+ src/epub2m4b.egg-info/requires.txt
9
+ src/epub2m4b.egg-info/top_level.txt
10
+ src/soundbook/__init__.py
11
+ src/soundbook/__main__.py
12
+ src/soundbook/cli.py
13
+ src/soundbook/config.py
14
+ src/soundbook/db.py
15
+ src/soundbook/models.py
16
+ src/soundbook/pipeline.py
17
+ src/soundbook/py.typed
18
+ src/soundbook/assemble/__init__.py
19
+ src/soundbook/assemble/concat.py
20
+ src/soundbook/assemble/loudnorm.py
21
+ src/soundbook/assemble/m4b.py
22
+ src/soundbook/assemble/silence.py
23
+ src/soundbook/ingest/__init__.py
24
+ src/soundbook/ingest/anchors.py
25
+ src/soundbook/ingest/chaptering.py
26
+ src/soundbook/ingest/classify.py
27
+ src/soundbook/ingest/clean.py
28
+ src/soundbook/ingest/loader.py
29
+ src/soundbook/ingest/metrics.py
30
+ src/soundbook/segment/__init__.py
31
+ src/soundbook/segment/segmenter.py
32
+ src/soundbook/tts/__init__.py
33
+ src/soundbook/tts/base.py
34
+ src/soundbook/tts/fake.py
35
+ src/soundbook/tts/kokoro_local.py
36
+ src/soundbook/tts/openai_compat.py
37
+ src/soundbook/tts/voices.py
38
+ src/soundbook/util/__init__.py
39
+ src/soundbook/util/atomic.py
40
+ src/soundbook/util/audio.py
41
+ src/soundbook/util/disk.py
42
+ src/soundbook/util/hashing.py
43
+ src/soundbook/util/process.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ epub2m4b = soundbook.cli:main
@@ -0,0 +1,12 @@
1
+ epub-extended==0.2.3
2
+ lxml>=5
3
+ click>=8
4
+ filelock>=3
5
+
6
+ [dev]
7
+ pytest
8
+ soundfile
9
+
10
+ [kokoro]
11
+ kokoro==0.9.4
12
+ misaki[zh]==0.9.4
@@ -0,0 +1 @@
1
+ soundbook
@@ -0,0 +1,11 @@
1
+ """Version and public identity of the package."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ #: Bumped whenever parsing/cleaning/segmentation semantics change.
6
+ PIPELINE_VERSION = "0.1.0"
7
+
8
+ #: Bumped when the on-disk segment audio format changes (invalidates audio_key).
9
+ AUDIO_FORMAT_VERSION = "1"
10
+
11
+ DIST_NAME = "epub2m4b"