Skip to content

Commit 7faff81

Browse files
fix(cli): preserve speaker labels in WebVTT cue text (#5233)
1 parent 9111d9f commit 7faff81

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎packages/cli/src/whisper/normalize.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ How are you
214214
]);
215215
});
216216

217+
it.each([
218+
["ALICE: Hello there", "ALICE: Hello there"],
219+
["ALICE: Hello\nBOB: Welcome", "ALICE: Hello BOB: Welcome"],
220+
["Hello there\nALICE: Welcome", "Hello there ALICE: Welcome"],
221+
["ALICE: Hello\nWelcome back", "ALICE: Hello Welcome back"],
222+
["HOST-NAME: Welcome", "HOST-NAME: Welcome"],
223+
["Alice: Hello there", "Alice: Hello there"],
224+
])("preserves the VTT cue payload %j", (payload, text) => {
225+
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`;
226+
const { words } = loadTranscript(tmpFile("speaker.vtt", vtt));
227+
expect(words).toEqual([
228+
{ text, start: 1, end: 3.5, id: "w0" },
229+
{ text: "How are you", start: 4, end: 6, id: "w1" },
230+
]);
231+
expect(loadTranscript(tmpFile("speaker-roundtrip.vtt", formatVtt(words))).words).toEqual(words);
232+
expect(loadTranscript(tmpFile("speaker-roundtrip.srt", formatSrt(words))).words).toEqual(words);
233+
});
234+
217235
it("parses VTT with short timestamps (MM:SS.mmm)", () => {
218236
const vtt = `WEBVTT
219237

‎packages/cli/src/whisper/normalize.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ function parseSrt(content: string): Word[] {
218218
}
219219

220220
function parseVtt(content: string): Word[] {
221-
// Strip the WEBVTT header and any metadata blocks
222-
const body = content.replace(/^WEBVTT[^\n]*\n/, "").replace(/^[A-Z-]+:.*\n/gm, "");
221+
const body = content.replace(/^WEBVTT[^\n]*\n/, "");
223222
// VTT is structurally similar to SRT (without numeric indices)
224223
const blocks = body.trim().split(/\n\n+/);
225224
const words: Word[] = [];

0 commit comments

Comments
 (0)