Repository navigation
feat(parsers): narration.json model and caption-array reader - #8938
Open
DhanushMurugesanG wants to merge 1 commit into
Open
DhanushMurugesanG wants to merge 1 commit into
DhanushMurugesanG wants to merge 1 commit into
Conversation
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 was referenced Nov 26, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/narrationreads, checks and writesnarration.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'saudio_meta.json.@hyperframes/parsers/caption-arrayfindsconst/let/varscriptandTRANSCRIPTcaption arrays in HTML, reads their words (with an optionallinetag), 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.jsonstays the record of what was generated. media-use writes it; it already keys voices by line id withpath,duration_sandwords. Nothing about it changes. In part 4,narration setupdates 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 ttsruns).narration.jsonis 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 fromaudio_meta.jsonby line id. Withoutaudio_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.jsonis the engine's output. It also holds music, effects and credits, and a run without--onlyreplaces the whole voice list, so a script written by hand into it would be lost on the next full run.If you'd rather have one file, the per-line fields (
text,voice,voiced) could move intoaudio_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 keyprovider: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'sfindCaptionArraydoes, but handleslet/varand both array names, and edits by source span so untouched words keep their exact text.package.json,package-subpaths.jsonandtsup.config.ts.Test plan
narration.test.ts(round trip with unknown keys kept, every problem named, invalid JSON,audio_meta.jsontimings by id with bad entries skipped, voice key, text helpers) andcaptionArray.test.ts(const/let/var,scriptandTRANSCRIPT, words with and withoutline, splice and shift leave other elements byte-identical).bun run --filter @hyperframes/parsers test: 66 files, 1,667 tests pass.bun run check:package-subpathsandnode scripts/check-test-reachability.mjspass.