Skip to content

Write HTML. Render video. Built for agents.

fix(cli): preserve speaker labels in WebVTT cue text (#5233)

Abdullah M. Nazif7faff8154f86
diff --git a/packages/cli/src/whisper/normalize.test.ts b/packages/cli/src/whisper/normalize.test.ts
index 81914c5ef3..f4c54f2680 100644
--- a/packages/cli/src/whisper/normalize.test.ts
+++ b/packages/cli/src/whisper/normalize.test.ts
@@ -214,6 +214,24 @@ How are you
]);
});
+ it.each([
+ ["ALICE: Hello there", "ALICE: Hello there"],
+ ["ALICE: Hello\nBOB: Welcome", "ALICE: Hello BOB: Welcome"],
+ ["Hello there\nALICE: Welcome", "Hello there ALICE: Welcome"],
+ ["ALICE: Hello\nWelcome back", "ALICE: Hello Welcome back"],
+ ["HOST-NAME: Welcome", "HOST-NAME: Welcome"],
+ ["Alice: Hello there", "Alice: Hello there"],
+ ])("preserves the VTT cue payload %j", (payload, text) => {
+ const vtt = `WEBVTT\nX-TIMESTAMP-MAP:LOCAL:00:00:00.000,MPEGTS:900000\n\n00:00:01.000 --> 00:00:03.500\n${payload}\n\n00:00:04.000 --> 00:00:06.000\nHow are you\n`;
+ const { words } = loadTranscript(tmpFile("speaker.vtt", vtt));
+ expect(words).toEqual([
+ { text, start: 1, end: 3.5, id: "w0" },
+ { text: "How are you", start: 4, end: 6, id: "w1" },
+ ]);
+ expect(loadTranscript(tmpFile("speaker-roundtrip.vtt", formatVtt(words))).words).toEqual(words);
+ expect(loadTranscript(tmpFile("speaker-roundtrip.srt", formatSrt(words))).words).toEqual(words);
+ });
+
it("parses VTT with short timestamps (MM:SS.mmm)", () => {
const vtt = `WEBVTT
diff --git a/packages/cli/src/whisper/normalize.ts b/packages/cli/src/whisper/normalize.ts
index 41c29dec67..3ef6fba8c0 100644
--- a/packages/cli/src/whisper/normalize.ts
+++ b/packages/cli/src/whisper/normalize.ts
@@ -218,8 +218,7 @@ function parseSrt(content: string): Word[] {
}
function parseVtt(content: string): Word[] {
- // Strip the WEBVTT header and any metadata blocks
- const body = content.replace(/^WEBVTT[^\n]*\n/, "").replace(/^[A-Z-]+:.*\n/gm, "");
+ const body = content.replace(/^WEBVTT[^\n]*\n/, "");
// VTT is structurally similar to SRT (without numeric indices)
const blocks = body.trim().split(/\n\n+/);
const words: Word[] = [];