updated stringclasses 1
value | note stringclasses 1
value | stages dict |
|---|---|---|
2026-10-30T13:26:31.992585+00:00 | Intermediates moved to bucket ktrapeznikov/audiobook-audio | {
"1_pdf": {
"state": "done",
"store": "https://huggingface.co/buckets/ktrapeznikov/audiobook-audio",
"files": [
"source/"
]
},
"2_text": {
"state": "done",
"files": [
"text/book.md",
"text/clean.md",
"text/chapters.json"
],
"stats": {
"chapters": 49
... |
- Repo layout (final outputs only)
- Bucket layout (intermediates, no commit rate limits)
- Methodology
- Stage 1 — Source (archive:
00_pdf/→ bucketsource/) - Stage 2 — Extraction and cleaning (
scripts/extract_and_chunk.py) - Stage 3 — Voice selection (
scripts/audition_voices.py) - Stage 4 — Synthesis (
scripts/synthesize.py) - Stage 5 — Assembly (
scripts/assemble_m4b.py) - Cost and wall-clock (actual)
- Known limitations
- Rerunning any stage
- Stage 1 — Source (archive:
audiobook-pipeline
Final outputs and pipeline scripts for the PDF → M4B audiobook conversion of Simon Abramovich Rosenberg's memoirs ("PERIODS OF LIFE — Memoirs", English literal translation, 94 pages). Single narrator, cloned voice, open-weights TTS, executed on Hugging Face Jobs. All intermediate artifacts live in the bucket ktrapeznikov/audiobook-audio.
Final output: 05_final/book.m4b — 5.89 h, 49
chapter markers, 224 MB (AAC 80 kbps mono, 24 kHz).
Repo layout (final outputs only)
| Path | Contents |
|---|---|
05_final/book.m4b |
The audiobook |
scripts/ |
All five pipeline scripts (extraction, audition, synthesis, consolidation, assembly) |
STATUS.json |
Stage manifest with stats |
Bucket layout (intermediates, no commit rate limits)
| Path | Contents |
|---|---|
source/ |
Raw PDF, exactly as received |
text/ |
book.md (raw extraction), clean.md, chapters.json (49 sections) |
chunks/ |
1,679 per-chunk WAVs, chunks.parquet manifest, synthesis_log.jsonl ledger |
auditions/ |
Voice audition clips + ref/andy_minter_zenda_ch01_15s.wav (cloning reference) |
book.m4b |
Copy of the final audiobook |
Methodology
Stage 1 — Source (archive: 00_pdf/ → bucket source/)
The uploaded PDF (654 KB, 94 pages) was archived unmodified. A text-layer assertion in the extraction step guards against scanned PDFs (aborts if a page yields < ~10 % of the expected characters; not triggered here — no OCR was needed).
Stage 2 — Extraction and cleaning (scripts/extract_and_chunk.py)
Extraction. pymupdf4llm.to_markdown(page_chunks=True) — pinned
pymupdf4llm<1 (the 2.0 PyPI release is an empty stub). Emits Markdown with
bold headings (### **N. TITLE**), which stage 2 later uses as its chapter
anchors.
Cleaning rules (in order, each logged with counts):
- Drop page-number and running-footer lines (93 lines matching
SIMON ABRAMOVICH ROSENBERG | MEMOIRS <n>and bare numerals). - De-hyphenate words broken across line breaks (
(\w)-\n(\w)→ join). - Expand TTS-hostile abbreviations: Dr.→Doctor, Mr.→Mister, Mrs.→Missus, St.→Saint, etc.→etcetera (conservative list only; dates and numerals are left to the TTS model).
- Strip paralinguistic tags (
[laugh],[chuckle], …) which the source never contained but which would otherwise be read literally. - Join hard-wrapped lines: a lone newline is a wrap, not a paragraph break.
- Strip Markdown syntax (heading markers, bold/italics), keeping the text — chapter headings become plain lines the narrator speaks as titles.
- Cut front matter: everything before the
INTRODUCTIONheading (title page + table of contents, 1,154 chars) — the TOC must not be narrated. - Merge mid-sentence paragraph fragments (2,987 merges): page breaks
inside sentences create false paragraph boundaries. Only
. ! ?(optionally followed by a closing quote) can terminate a sentence — a trailing comma, semicolon, colon or closing quote means the sentence continues. Paragraphs starting with a heading-like pattern (^\d{1,2}\.) are exempt so chapter headings never absorb preceding text.
Chapter detection. Bold headings in the raw Markdown are the anchor (34 numbered chapters + 15 front/back-matter sections = 49). A sequence-based rescue pass recovers headings whose bold markup was lost in extraction (chapter 29, whose number sequence skips 30 — chapter 30 exists only in the TOC). Headings are then mapped into cleaned-text coordinates by sequential title search with a whitespace-normalized fallback.
Chunking. spaCy en_core_web_sm sentencizer, per paragraph; chunks are
built from whole sentences targeting ~250 chars (hard cap 700) and never
straddle a paragraph boundary, so the narrator pauses at natural paragraph
edges. Chunks carry true character offsets (no string-search guessing).
Final chunk stats (1,679 chunks): length min 156 / p50 191 / max 257 chars; 0 newlines; 0 markdown residue; 2 mid-sentence chunk starts; 13 non-terminal endings (headings and list fragments — intended).
QA gates. The script hard-fails (rather than proceeding) if any chunk contains a newline or if >80 chunks end mid-sentence; an audit pass over all 1,679 chunks additionally checks markdown residue, footers, TOC fragments, unexpanded abbreviations, double spaces, punctuation spacing, bracket balance and lowercase chunk starts. The chunk-level review gate (20-row human sample) passed with no rejections.
Stage 3 — Voice selection (scripts/audition_voices.py)
Three candidates rendered the same three passages (opening, mid-book, final paragraph) for side-by-side audition:
- Kokoro-82M (
hexgrad/Kokoro-82M, Apache-2.0) British male presetsbm_georgeandbm_fable— very stable, flatter delivery. - Chatterbox-Turbo (
ResembleAI/chatterbox-turbo, MIT) cloning Andy Minter (1934–2017), an elderly British LibriVox reader, from a 15 s clip of The Prisoner of Zenda chapter 1 (archive.org, public domain; cut with a static ffmpeg fromimageio-ffmpeg, resampled to 24 kHz mono). Committed to the bucket atauditions/ref/andy_minter_zenda_ch01_15s.wav.
The clone was selected by the listener for its documentary-narrator character. Trade-off noted at audition time: cloned voices can drift over 1,679 chunks, so any suspect passage can be regenerated individually (every chunk is an independent generation).
Stage 4 — Synthesis (scripts/synthesize.py)
- Model:
chatterbox-tts==0.1.7→ChatterboxTurboTTS.from_pretrained(device="cuda"); generation viamodel.generate(text, audio_prompt_path=<Minter ref>)with default parameters (repetition_penalty 1.2, temperature 0.8, top_p 0.95, norm_loudness on) and a fixed seed (1234). Output 24 kHz mono. - Sharding: chunk i belongs to shard
i % 32; 32 concurrenta10g-smalljobs ($1.00/h each) each take ~52 chunks. - Resume: the skip-set is derived from files that already exist (dataset
repo
03_audio/in the first wave, bucketchunks/thereafter) — a rerun regenerates only missing chunks. The ledger (chunks/synthesis_log.jsonl: chunk id, chars, audio seconds, generation seconds) is informational and best-effort. - Storage lesson: the first wave wrote per-chunk WAVs to the dataset repo (a git commit per batch) and exhausted the Hub's 256 commits/hour limit within minutes. Audio moved to a mounted bucket (plain file writes, no git) — chunk WAVs, ledger and final M4B are all bucket files.
- Measured pace: RTF 0.45 generating, 0.78 including model load and I/O (~9.5 s wall per ~12 s audio chunk). 1,679 chunks ≈ 4.4 GPU-hours; at 32× parallelism the generation wave completed in ~6 minutes of wall clock. The final 87 missing chunks were regenerated in one 8.5-minute job.
- Environment pins:
torch==2.6.0,torchaudio==2.6.0,chatterbox-tts==0.1.7(pinsnumpy<2on Python <3.13),setuptools<81(the PerTh watermarker importspkg_resources; its silentexcept ImportErrorotherwise crashes model loading),pandas==2.2.3,pyarrow==21.0.0,trackio==0.44.0.
Stage 5 — Assembly (scripts/assemble_m4b.py)
Per chapter: chunks concatenated with 0.35 s silence between chunks.
Across chapters: 0.9 s. Concatenated to a full-book WAV (PCM, 24 kHz mono),
encoded to AAC 80 kbps mono, and muxed to M4B (-f ipod) with chapter
markers generated from per-chapter WAV durations (FFMETADATA format).
Boundary arithmetic uses the WAV sample counts, so chapter starts are
sample-accurate. The M4B is written to the bucket first (no commit
limit) and then uploaded to this repo with rate-limit-aware retries.
Cost and wall-clock (actual)
| Stage | Compute | Cost |
|---|---|---|
| Extraction + chunking (CPU) | ~1 min × 4 runs | ~$0.02 |
| Smoke test (a10g-small) | 3.5 min | $0.06 |
| Voice auditions (a10g-small) | 2.5 min | $0.05 |
| Generation, all waves (a10g-small × 32) | ~7 GPU-h | ~$7.70 |
| Assembly (CPU) | 13 min | ~$0.75 |
| Total | ≈ $8.60 |
Total wall clock from PDF to M4B, including all failed waves and voice iterations: ~3 h. A clean rerun of the whole pipeline is ~15 min.
Known limitations
- 2 chunks start mid-sentence (sentence-split artifacts in the source text); inaudible in practice, since the same voice continues.
- 3 orphan brackets (e.g. a bare
(p.) from footnote extraction. - One source-text gap ("transferred to prison in ." — the date is missing in the PDF itself).
- The 12 chunks first generated with the preset voice were deleted and regenerated with the Minter clone, so the whole book is one voice.
Rerunning any stage
Each script in scripts/ reads its inputs from the previous stage's
committed outputs (repo or bucket) and skips work already present — e.g.
synthesize.py --mode all --voice minter regenerates only chunk WAVs
missing from the bucket, and assemble_m4b.py rebuilds the M4B from the
bucket in ~13 CPU-minutes. Pipeline: pymupdf4llm extraction → text
normalization → spaCy sentence chunking → Chatterbox-Turbo (voice clone) →
ffmpeg → M4B.
- Downloads last month
- 402