diff --git a/packages/cli/src/whisper/transcribe.metadata.test.ts b/packages/cli/src/whisper/transcribe.metadata.test.ts index 057c79db39..7099cb62bd 100644 --- a/packages/cli/src/whisper/transcribe.metadata.test.ts +++ b/packages/cli/src/whisper/transcribe.metadata.test.ts @@ -221,6 +221,18 @@ it("never streams a segment that starts before what was already streamed", async expect(words.map((event) => event.words.map((word) => word.text))).toEqual([["later"]]); }); +it("streams a zero-length first segment once, however often whisper reprints it", async () => { + native.printed.stdout = + "[00:00:00.000 --> 00:00:00.000] uh\n" + + "[00:00:00.000 --> 00:00:00.000] uh\n" + + "[00:00:00.000 --> 00:00:02.000] Hello world\n"; + const { words } = await transcribeStreaming(); + expect(words.map((event) => event.words.map((word) => word.text))).toEqual([ + ["uh"], + ["Hello", "world"], + ]); +}); + it("reports progress through audio where whisper prints no segment, once per step", async () => { writeFileSync(join(dir, "audio.wav"), Buffer.alloc(4 * 32_000)); native.printed.stderr = diff --git a/packages/cli/src/whisper/transcribe.ts b/packages/cli/src/whisper/transcribe.ts index 03ef5860e7..c948468650 100644 --- a/packages/cli/src/whisper/transcribe.ts +++ b/packages/cli/src/whisper/transcribe.ts @@ -540,7 +540,7 @@ export async function transcribe( overrideMs: options?.timeoutMs, }); let through = 0; - let streamedUntil = 0; + let streamedUntil = -1; const heard = (words: Word[], at: number) => { if (!onEvent || (words.length === 0 && at <= through)) return; through = Math.max(through, at); @@ -555,7 +555,7 @@ export async function transcribe( ((line) => { const segment = segmentWords(line); // With word timing on, whisper.cpp reprints its first window's segments out of order. - if (!segment || segment.start < streamedUntil) return; + if (!segment || segment.start < streamedUntil || segment.end <= streamedUntil) return; streamedUntil = segment.end; heard(segment.words, segment.end); }),