mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 22:58:02 +00:00
fix(cli): a reprinted zero-length segment streams once
The stream guard kept any segment starting at the high-water mark, so a zero-length first segment passed on every reprint. A segment that ends no later than what was already streamed is dropped too; the mark starts below zero so the first segment, even at 0 s, still streams.
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user