Rebuilt from a behaviour spec by an implementer who never saw the removed code (batch O: #2278, #2205, #2157).
(cherry picked from commit 72d49954a9faf0c591ba9d37ae25e8362253ab02)
Removes code from contributors without a CLA on file, leaving CLEAN-ROOM markers where the reimplementation goes.
(cherry picked from commit 1ac12d16bacef204069252ab042897aef324803b)
Rewritten from a behavioural spec by an implementer without access to the
removed code, so every line has CLA-covered provenance. Same request fields,
render-summary shape, i18n keys and parser behaviour; UI, wording and
translations are new.
(cherry picked from commit de0d33aa3cae8d009276b6dba661dbf4d77d29e2)
Removes code from contributors without a CLA on file, leaving CLEAN-ROOM markers where the reimplementation goes.
(cherry picked from commit 53b6f6d6348ee655817b114ee248d3d4ac5ea24f)
Protect chapter, segment, and atomic staging WAVs from overlapping cache
pruning. Defer eviction until render cleanup to preserve oversized-book
resume progress, and retain checkpoints when FFmpeg assembly fails.
* feat(longform): download a chapter cue sheet after a render
Implements spec 33 (docs/specs/longform/33-cue-sheet-export.md).
An M4B embeds its chapters. MP3 has no portable way to carry them, and
nothing at all travels with the audio when someone wants timestamps for
show notes, a podcast platform, or a player that ignores embedded
chapters. A finished Stories or Audiobook render now offers the chapters
as a .txt — `HH:MM:SS<TAB>Title`, one line each.
The data was already there and already thrown away. The renderer streams
`duration_s` per chapter, and longform-session keeps it with a status, so
no backend change, no new endpoint and no new dependency: the sheet is
built from `draft.outputChapters` at download time.
The one invariant that matters is which chapters count. The backend
appends to `chapters_meta` — the source of the M4B's embedded FFMETADATA
chapters — only after a chapter renders, and skips past a failure, so a
failed chapter occupies no time in the finished file. Give it a cue and
every later timestamp is wrong by its would-be duration. That filter, and
the decision that there is nothing worth downloading, live in one tested
function rather than inline in the page.
The accumulator is total by construction: a missing, negative or
non-numeric duration contributes zero instead of poisoning every later
start time, and an untitled chapter falls back to its position. So a
sheet is never silently wrong when a chapter arrives malformed.
The spec asks for a TAB separator, and this follows it — a space cannot
be split from a title that contains spaces. Worth flagging: the spec also
lists YouTube chapters as a use case, and YouTube wants `00:00:00 Title`.
Happy to switch the separator, or emit both, if you'd rather serve that
case directly.
Two shared helpers gain a home next to the existing `formatTimecode` /
`buildCueSheet`, which had no production caller at all before this — only
their own tests. `buildCueSheet` moves from a space to a TAB per the
spec; its one existing assertion is updated in place, and nothing else
referenced it.
Per the spec's docs-sync instruction, re-grepped README.md and docs/ for
anything enumerating export formats: `docs/electron-longform.md` names
MP3 and M4B, so the cue sheet is named alongside them.
36 tests — 25 on the pure helpers (accumulation, monotonicity under bad
input, title fallback, filename derivation incl. the anchored-regex
length guard), 11 on what a render contributes (cached chapters count,
failed ones do not, nothing offered when every chapter failed).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(longform): exact cue-sheet timestamps and native save for #2278
- Backend chapter event gains additive `duration_ms`, the exact value
written into the m4b FFMETADATA chapters; cues accumulate integer ms
(falling back to duration_s for older backends), so starts match the
embedded chapters and float sums can no longer floor a second early.
- Non-finite durations (incl. +/-Infinity) contribute zero.
- Only done/cached chapters get a cue (allow-list, not "not failed").
- Cue sheet is gated on a finished output file.
- Save through saveLocalFile (native dialog in Electron) with error
surfacing, instead of a raw blob anchor revoked synchronously.
- Untitled chapters use the localized audiobook.chapter_n label.
- Filename helper also strips Windows path prefixes.
- Changelog one-liner credits @shivsin25; docs updated.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(changelog): drop unrelated issue ref from cue sheet entry
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(longform): keep cue sheet titles on one line and in one field
A tab or line break in a chapter title added a field or a line to the
TAB-separated cue sheet. buildCueSheet now collapses tabs and line
breaks (CR/LF, VT, FF, NEL, U+2028/2029) to one space, and
cuesFromChapters normalises before its blank-title fallback.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* style(frontend): oxfmt storyExport.js
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(longform): ignore a blank duration_ms in cue sheets; credit highlight
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Shivendra-Coherent <shivendra@coherentmarketinsights.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Palash Debnath <4178343+debpalash@users.noreply.github.com>
- Summarise only the chapters that rendered (failed ones are not in the file)
and record the language synthesis actually used (resolved, not 'Auto').
- Record options that differ from the defaults by VALUE, so an explicit seed=0
or postprocess_output=False is kept and untouched defaults are not.
- The summary is recovered from a stored event, so the library coerces it to
exactly the shape clients read; the client guards its list reads too. A
malformed record degrades to fewer details instead of crashing Projects.
- Leave the point-in-time QA spec untouched; the new fields are documented in
docs/electron-longform.md.
A finished Story or Audiobook in Projects was a bare filename: the library is
recovered from the render's 'done' event, which carried no title and nothing
about how the file was produced.
- The renderer now records 'title' and a content-free 'summary' on the done
event: engine, voices (id + profile name), language, format, line and word
counts, distinct speeds, the non-default expressive options and chapter
titles. Settings and counts only, never script text. Best-effort: a summary
failure never fails a render (tested).
- build_longform_library passes the summary through; older renders have none.
- Projects rows show the title and a one-line recipe (voice, speed, engine,
length); 'How it was made' expands to the full details. 21 locales.
Tests: pure summary, library pass-through and malformed summary, end-to-end
done event, summary failure isolation, RenderDetails component.
The report arrived as a raw traceback pasted out of a log file — because that is the only place the reason existed. A failed chapter was a red row and the word "failed"; the SSE event carried the literal string "chapter failed to render", the symptom the user could already see.
- Both the per-chapter and the terminal all-failed events are now built with the shared `core.failure` builder: sanitized text, a guaranteed non-empty reason, error class, docs deeplink and hint. `error` keeps mirroring `reason`, so older frontends and the Stories exporter are unaffected. The chapter list shows the reason inline, full text in the row tooltip.
- **A silent infinite hang on the same path.** asyncio refuses to put `StopIteration` into a Future — `_copy_future_state` raises TypeError inside the event loop's own callback, so the `run_in_executor` future is never completed and the caller waits forever, with no error, event or timeout. Reachable from ordinary input: VoxCPM's `next_and_close` is a bare `next(gen)`, so a generator ending without yielding raises it straight into a GPU-pool worker. Fixed at the pool boundary (`_ResilientGpuPool.submit` plus a matching `_cpu_pool` subclass) as `WorkerStopIteration(RuntimeError)`, keeping the original as `__cause__`.
- An all-failed render now marks the job failed. It previously returned without touching job history, so the row stayed `running` and the next startup's orphan sweep read a hopeless render as interrupted and offered it as resumable (Greptile P1).
Tests: 6 pool-guard tests (two hang without the fix, bounded so a hang fails rather than stalls CI), longform e2e extended for both event shapes, the empty-`str(exc)` floor, and both sides of the job-status branch, plus the chapter-list component.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Audiobook renders were locked to the model's most deterministic preset (32
steps / 2.0 guidance / model-default temps) with no way to change it, which is
why books sounded flatter than the same voice on the Voice page. Open that up
without changing any default byte-for-byte.
- Production Overrides in the Audiobook tab: position_temperature,
class_temperature, num_step, guidance_scale, postprocess_output (+ seed),
reusing the Voice page's panel. Unset reproduces today exactly.
- IndexTTS2 graded emotion (emo_vector / emo_text / emo_alpha) reaches the
longform path via a typed engine-options object; engines that don't
understand an option ignore it (no crash across the ~14 backends).
- Cache opt-out ("vary repeated lines") so identical lines can get distinct
takes; default off keeps the content-addressed replay.
- Markup reference now lists the reaction tags that already work in audiobooks;
docs/expressive-speech.md corrected so no recipe it names is unreachable.
- Fix AudiobookGenerateBody dropping `language`, so audiobook language
selection actually reaches the backend.
Every new param is folded into BOTH cache layers (chapter + segment) and the
per-chapter preview, so changing a knob re-renders instead of replaying stale
audio — and an all-default request keeps its old cache key, so existing books
don't re-render. Regression tests: tests/test_audiobook_expressive.py (backward
compat, cache-signature loop, preview/render parity, engine-ignores-unknown,
cache opt-out, emotion reaches engine) + audiobookOverrides.test.jsx.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Non-English voices drifted to English/wrong-language because the request's or
profile's language wasn't reaching the model:
- #533: generate_speech() read instruct/ref_text/seed from a resolved profile row
but never row['language'] (and collapsed Auto→None), so a German archetype
previewed in German yet generated in English on the user's own call (and via
Docker/API). Fall back to the profile's stored language when the request didn't
pin one; an explicit non-Auto request language still wins. (Frontend already
sets the dropdown on profile-select; this is the authoritative backend fix.)
- #505 (B2): the audiobook/longform synth hardcoded language=None, so the engine
re-autodetected per chunk and a non-English clone flipped language mid-render.
Add _resolve_default_language (request → profile → autodetect) and thread the
resolved language through _build_synth/_prepare_synth/_render_longform_sse, the
three longform request models, the preview path, and the resume manifest.
Genuine Auto/unset behavior is unchanged.
- #502 (partial): the duration estimator weights combining marks (U+0300–036F)
at 0.0, so NFD/decomposed text under-allocated frames → rushed audio. NFC-
normalize text at the estimator entry — fixes the whole diacritic-script class
(no-op for precomposed text). (The residual "distorted" core still needs the
reporter's sample; tracked separately.)
Tests (fail-before/pass-after): profile language reaches the engine (German→de;
explicit/Auto override semantics); longform synth gets the resolved language
(→ja), not None; NFD vs NFC duration parity (Korean Hangul diverges ~3x pre-fix).
Full suite: tests/ 1740 passed, backend/tests/ 114 passed.
Co-authored-by: mergetest <test@local>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat(longform): two-pass loudnorm measure orchestrator + wiring (#28 slice 2)
Completes accurate ACX/podcast mastering end-to-end (builds on the pure builders
from #28 slice 1).
- `services/loudness.py` — `measure_loudness(ffmpeg, concat, preset, *, job_id)`:
runs ffmpeg's measure pass, parses the loudnorm JSON → MeasuredLoudness.
**Never raises** — skip / non-zero rc / rc None / asyncio.TimeoutError / spawn
OSError / empty or unparseable stderr / silent program all WARN + return None
→ single-pass fallback (a slow/broken measure degrades the master, never
aborts the render). Logs rc + a static message only, never the raw stderr
(path-safe / local-first). UTF-8 decode with replacement (Windows-cp safe).
- `_render_longform_sse` (audiobook.py): between the concat write and the mux,
when `loudness` is a known preset (acx/podcast; same `.lower()`/no-strip gate
as the builders) → emit a `mastering` event, measure, and pass `measured` into
`build_render_cmd` (two-pass apply; `None` → single-pass). `done` gains a
`loudness` block {preset, target_i, target_tp, two_pass, measured_i} ONLY for
a requested preset — off/None paths keep the byte-identical legacy `done`
shape. Both front doors (/audiobook + /longform/render) get it via the shared
generator. Chapter cache key is deliberately untouched (loudness-agnostic →
acx/off reuse the same cached WAVs; no re-render, no cache-layout break).
Tests: `test_loudness.py` (14 — happy fixture, skip-without-spawn for off/
unknown/whitespace/None, non-zero/None rc, timeout-not-propagated, OSError,
empty/unparseable stderr, non-UTF-8 stderr, job_id+argv forwarding) + 2 e2e
cases (mastering event + done.loudness present for acx; absent for off). Orch
tests run locally (stubbed run_ffmpeg, no torch); e2e on CI.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(loudness): lazy-import run_ffmpeg so the measure stub survives sys.modules purges
test_loudness monkeypatched services.loudness.run_ffmpeg, but the route-shape
fresh_app fixture purges services.* from sys.modules, so under the full-suite
ordering the patch missed the re-imported module → real ffmpeg ran → 3 failures.
Lazy-import run_ffmpeg inside measure_loudness and patch it at its source
(services.ffmpeg_utils.run_ffmpeg) so the stub is always picked up at call time.
Verified by running the purging suite + test_loudness together (31 pass).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
#34 runtime-verify Layer 1 — the cheap regression net over the audiobook /
stories convergence. Drives the REAL `_render_longform_sse` generator + REAL
ffmpeg with a stub CPU-tone synth (no GPU/model), and ffprobes the muxed output.
Covers happy m4b (full SSE sequence + 2 tagged chapters), mp3 container,
per-chapter partial failure (chapter_error isolates ch.0, surviving chapter
still muxes), total failure (error + NO file), empty plan, and the no-ffmpeg
branch. Gated on ffmpeg present (skip otherwise; runs in CI).
Like the other endpoint tests it imports the app+torch stack, so it's validated
on CI (local pytest segfaults on the pre-existing torch/Triton import).
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>