Skip to content

feat(parsers): narration.json model and caption-array reader - #8938

Open
DhanushMurugesanG wants to merge 1 commit into
heygen-com:mainfrom
DhanushMurugesanG:narration/1-parsers
Open

DhanushMurugesanG wants to merge 1 commit into
heygen-com:mainfrom
DhanushMurugesanG:narration/1-parsers

Conversation

@DhanushMurugesanG

@DhanushMurugesanG DhanushMurugesanG commented Nov 26, 2026 •

Copy link
Copy Markdown

Part 1 of 4 for linked narration (#6708), split as suggested there. This one adds code nothing uses yet; parts 2 to 4 build on it.

What

Two new subpaths in @hyperframes/parsers:

  • @hyperframes/parsers/narration reads, checks and writes narration.json, the script of a narrated project: each line's text, voice and audio file, and what it was last voiced from (voiced: hashes of the text, the voice settings and the WAV). Keys it doesn't know are kept on rewrite. narrationTimingsOf() reads each line's length and word timings from media-use's audio_meta.json.
  • @hyperframes/parsers/caption-array finds const/let/var script and TRANSCRIPT caption arrays in HTML, reads their words (with an optional line tag), and splices or shifts words while every other element stays byte-identical.

No behaviour change.

Why

#6708: a voice-over and its captions are made once and then drift apart. Lint (part 2) and the CLI (parts 3 and 4) need one shared reading of the script and of the caption arrays, and lint depends only on parsers, so the shared code lives here.

narration.json and audio_meta.json

You asked which file is the source of truth, and whether one file could do both jobs. My proposal is two files, one job each:

  • audio_meta.json stays the record of what was generated. media-use writes it; it already keys voices by line id with path, duration_s and words. Nothing about it changes. In part 4, narration set updates the re-voiced line's entry by id (the same merge-by-id fix(media-use): keep the other voices when a TTS run re-voices some lines #6816 adds for partial --only tts runs).
  • narration.json is the script: what each line should be. Its text, voice, audio file, the caption array that shows it, and what it was last voiced from. It never copies lengths or word timings; those are read from audio_meta.json by line id. Without audio_meta.json (a project voiced some other way), lint still checks text, audio and links, and only asks that a line's captions fall inside its clip.

Why not one file:

  • audio_meta.json is the engine's output. It also holds music, effects and credits, and a run without --only replaces the whole voice list, so a script written by hand into it would be lost on the next full run.
  • Lint would have to treat an engine output as the user's input, and every media-use format change would become a narration format change.

If you'd rather have one file, the per-line fields (text, voice, voiced) could move into audio_meta.json's voices. Only the reader here and the writers in parts 3 and 4 would change, so it's cheap to switch now, before anything depends on it.

Related work

Refs #6708. #7861 asks for narration anchors that fail the build when a script edit removes a word; that would build on these line ids. #6816 (merge voices by id on --only tts) is separate and independent.

The series: #8938 (this one) → #8939 (lint rules) → #8940 (narration list / init / check) → #8941 (narration set).

How

  • narration.ts: the model, parseNarrationManifest (every problem listed, not just the first), serializeNarrationManifest (two-space JSON, key order kept), the voice key provider:voice:speed:lang, whitespace-normalised text for hashing, and comparable words for caption checks. Line ids are plain names, since they appear in attributes and caption tags.
  • captionArray.ts: uses acorn, the same way the CLI's findCaptionArray does, but handles let/var and both array names, and edits by source span so untouched words keep their exact text.
  • Two subpaths in package.json, package-subpaths.json and tsup.config.ts.

Test plan

  • Unit tests added/updated: narration.test.ts (round trip with unknown keys kept, every problem named, invalid JSON, audio_meta.json timings by id with bad entries skipped, voice key, text helpers) and captionArray.test.ts (const/let/var, script and TRANSCRIPT, words with and without line, splice and shift leave other elements byte-identical).
  • bun run --filter @hyperframes/parsers test: 66 files, 1,667 tests pass. bun run check:package-subpaths and node scripts/check-test-reachability.mjs pass.
  • Manual testing: the whole series was run end to end with real Kokoro voices and whisper captions (see part 4).
  • Documentation updated: nothing user-facing yet; parts 2 and 3 add the docs.
  • Comments say why, not what.

Adds two subpaths that later narration work builds on. No behaviour
changes: nothing imports them yet.

- @hyperframes/parsers/narration: reads, checks and writes
  narration.json, the script of a narrated project (each line's text,
  voice, audio file and what it was last voiced from), keeping unknown
  keys. Lengths and word timings are not copied into it:
  narrationTimingsOf() reads them from media-use's audio_meta.json by
  line id.
- @hyperframes/parsers/caption-array: finds const/let/var `script` and
  `TRANSCRIPT` caption arrays in HTML, reads their words, and splices or
  shifts words while every other element stays byte-identical.

Refs heygen-com#6708

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant