Skip to content

feat(cli): narration set re-voices one line - #8941

Open
DhanushMurugesanG wants to merge 4 commits into
heygen-com:mainfrom
DhanushMurugesanG:narration/4-set
Open

DhanushMurugesanG wants to merge 4 commits into
heygen-com:mainfrom
DhanushMurugesanG:narration/4-set

Conversation

@DhanushMurugesanG

Copy link
Copy Markdown

Part 4 of 4 for linked narration (#6708). Builds on #8938, #8939 and #8940: until they merge, this PR also shows their commits. Only the last commit (feat(cli): narration set re-voices one line) is new here.

What

hyperframes narration set <id> [text] re-voices one line and updates everything that depends on it, together, as one history entry:

  • the clip's src and data-duration
  • that line's caption words (tagged with the line), re-timed from the new take
  • caption-overrides.json: indices after the line move; the line's own overrides stay only if its word count is unchanged
  • narration.json: the text, voice and voiced record
  • the line's voice in audio_meta.json (path, length, words), with total_duration_s summed again

Flags: --voice, --speed, --dry-run, --no-retime, --force, --who, --dir, --json.

Why

#6708: editing one line should re-voice that line and keep its captions and timing in step, without regenerating the whole voice-over.

Voices that don't repeat

set re-voices one line on its own, so the new take has to sound like the lines around it. That holds for a local voice: Kokoro gives the same audio for the same text and settings. A service whose voices may vary between calls could make an edited line sound different from its neighbours, so set refuses any provider other than Kokoro and says why:

narration set re-voices one line with Kokoro only, a local voice that sounds the same each time, so the line matches its neighbours. heygen voices may not repeat; re-voice every line with media-use (--only tts) instead

If a provider can promise repeatable output later (a fixed seed, say), it could be allowed by name.

Related work

Refs #6708. Completes the series: #8938, #8939, #8940, then this.

How

  • The take is voiced (synthesize) and transcribed (runTranscribe) in a scratch folder outside the project. Transcribing inside the project would rewrite every caption array in it. A take with no words heard is refused.
  • narration/planSet.ts plans every change without writing. The apply step copies the WAV to assets/voice/<id>-<hash8>.wav, then calls applyFileMutations with each file's version from before the slow voicing step, so a file edited in the meantime refuses the write ("changed while the line was re-voiced; run the command again"). The old WAV is kept, so history undo never points a clip at a missing file.
  • A longer take that would run into the next narration clip on the same track is refused, unless --no-retime. Moving later clips is left out of this PR.
  • audio_meta.json is updated only if the project has one, written as media-use writes it (two-space JSON). Other fields of the voice entry, and the rest of the file, are kept.
  • Lint's fix hints now name narration set.

Test plan

  • Unit tests added/updated: narration/set.test.ts, with synthesize and runTranscribe mocked as in tts.test.ts. It covers:
    • only line l2's clip, caption words, later override indices, manifest entry and audio_meta.json voice change, and lint is clean afterwards
    • voicing and transcribing happen outside the project; an unchanged line is left alone; a dry run writes nothing
    • overlap refused or kept with --no-retime; a file changed mid-run refuses the write and leaves no WAV
    • overrides kept on an equal word count; one history entry, undone in one step (audio_meta.json included)
    • a non-Kokoro provider refused; no audio_meta.json; the command line with --json
  • Manual testing, with real Kokoro (af_heart) and whisper (small.en) on a 3-line project made the way media-use leaves one:
    1. narration init, then check: in sync.
    2. Edit l2's text in narration.json, then check: narration_audio_stale plus a transcript info.
    3. set l2 --dry-run, then set l2: 1.707 s, 5 words; files index.html, audio_meta.json, narration.json.
    4. check and lint: 0 narration findings. A take that runs into l3 is refused.
    5. history undo restores every file, audio_meta.json included.
  • Documentation updated: set in docs/packages/cli.mdx, and the lint fix hints.
  • 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
A project with narration.json now gets a warning when a line's text,
voice or WAV changed since it was voiced, when a line has no linked
clip or its clip is the wrong length, and when the caption words that
show it no longer match its voice. Captions that read differently from
the script get an info. No manifest, no findings, and nothing blocks a
render.

Lengths and word timings come from media-use's audio_meta.json by line
id. Without it, the length isn't checked and a line's captions only
need to fall inside its clip.

Refs heygen-com#6708
- init writes narration.json for a project voiced before it existed:
  from media-use's audio_meta.json and audio_request.json, or from clips
  already tagged with data-narration-line and the caption words inside
  them. It tags each line's clip, as one history entry. Lengths and word
  timings stay in audio_meta.json.
- list shows each line, its length from audio_meta.json and its
  narration findings, or "in sync".
- check prints the narration findings from lint and exits 1 while any
  warning remains.

Every subcommand takes --dir and --json and answers the same with
--json before or after it. A refusal (no narration.json, nothing to
adopt) exits 2 with its message.

Refs heygen-com#6708
`hyperframes narration set <id> [text]` voices the line with Kokoro in a
scratch folder, transcribes that clip alone, then changes together, as
one history entry: the clip's src and data-duration, that line's caption
words, caption-overrides.json (indices after the line move; the line's
own overrides stay only if its word count is unchanged), narration.json,
and the line's voice in audio_meta.json (path, length, words).

- The take goes to assets/voice/<id>-<hash>.wav and the old WAV is kept,
  so history undo always finds the audio it points back to.
- A longer take that would run into the next narration clip is refused
  (--no-retime keeps it); --dry-run writes nothing; an unchanged line is
  left alone unless --force.
- A file edited while the line is voiced refuses the write.
- Only Kokoro: a local voice gives the same audio for the same text, so a
  re-voiced line sounds like its neighbours. Voices that may not repeat
  are refused with a pointer to re-voicing every line with media-use.

Lint's fix hints now name narration set.

Refs heygen-com#6708
@mintlify

mintlify Bot commented Nov 26, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit a34fabb.

Approve preview

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