diff --git a/packages/cli/src/commands/transcribe.test.ts b/packages/cli/src/commands/transcribe.test.ts index 76d327211a..4b7108c9b0 100644 --- a/packages/cli/src/commands/transcribe.test.ts +++ b/packages/cli/src/commands/transcribe.test.ts @@ -7,10 +7,11 @@ import { CliRuntimeError, consumeCommandResult } from "../utils/commandResult.js // Make the whisper core report "unavailable" so we exercise the soft-skip path. const transcribeMock = vi.fn(); +let audioSeconds = 1; vi.mock("../whisper/transcribe.js", () => ({ transcribe: transcribeMock, prepareWav: (input: string) => input, - getPreparedWavDurationSeconds: () => 1, + getPreparedWavDurationSeconds: () => audioSeconds, })); // Engine selection: which runners look installed, and the sherpa decode child it spawns. @@ -207,12 +208,12 @@ describe("transcribe command", () => { }); it("an explicit --engine parakeet fails with the Parakeet error instead of falling back", async () => { - crashChild("SIGABRT", "Protobuf parsing failed\n"); + crashChild("SIGABRT", "Protobuf parsing failed.\n"); Object.assign(runners, { sherpa: true, mlx: false }); const { exitCode, out } = await transcribeFails("parakeet"); expect(exitCode).toBe(1); expect(out.error).toMatch( - /^Parakeet failed: .*Protobuf.*hyperframes models install parakeet$/, + /^Parakeet failed: .*Protobuf parsing failed\. To repair it, run: hyperframes models install parakeet$/, ); expect(transcribeMock).not.toHaveBeenCalled(); }); @@ -236,6 +237,21 @@ describe("transcribe command", () => { expect(transcribeMock).not.toHaveBeenCalled(); }); + it("gives the decode at least 30 minutes, and twice the audio length", async () => { + Object.assign(runners, { sherpa: true, mlx: false }); + for (const [seconds, timeout] of [ + [60, 1_800_000], + [3600, 7_200_000], + ]) { + audioSeconds = seconds!; + const { dir, input } = dummyAudio(); + dirs.push(dir); + await transcribeCmd.run!({ args: { input, json: true, engine: "auto" } } as never); + expect(execFileMock.mock.calls.at(-1)?.[2]).toMatchObject({ timeout }); + } + audioSeconds = 1; + }); + it("succeeds with 0 words when the audio has no speech", async () => { execFileMock.mockImplementation((_cmd, _args, _opts, done) => { done(null, `HYPERFRAMES_PARAKEET_RESULT:${JSON.stringify([])}\n`, ""); diff --git a/packages/cli/src/commands/transcribe.ts b/packages/cli/src/commands/transcribe.ts index a3937ff49d..cb15d1d7b1 100644 --- a/packages/cli/src/commands/transcribe.ts +++ b/packages/cli/src/commands/transcribe.ts @@ -341,7 +341,8 @@ async function transcribeAudio( result = await run(runner); } catch (err) { if (runner !== "sherpa" || err instanceof DecodeCancelled) throw err; - const parakeetError = `Parakeet failed: ${normalizeErrorMessage(err)}. To repair it, run: hyperframes models install parakeet`; + const reason = normalizeErrorMessage(err).replace(/\.+$/, ""); + const parakeetError = `Parakeet failed: ${reason}. To repair it, run: hyperframes models install parakeet`; if (!parakeetFallsBack(engine)) throw new Error(parakeetError); runner = pickRunner(engine, () => false); spin?.clear(); diff --git a/packages/cli/src/whisper/sherpa.test.ts b/packages/cli/src/whisper/sherpa.test.ts index 69eb6613e7..789934b02a 100644 --- a/packages/cli/src/whisper/sherpa.test.ts +++ b/packages/cli/src/whisper/sherpa.test.ts @@ -45,7 +45,9 @@ describe("installSherpaRuntime", () => { const run = vi.fn(async (_args: string[]) => { throw new Error("stop before touching the cache"); }); - await installSherpaRuntime({ run }).catch(() => undefined); + const cancel = new AbortController(); + await installSherpaRuntime({ run, signal: cancel.signal }).catch(() => undefined); + expect((run.mock.calls[0] as unknown[] | undefined)?.[1]).toBe(cancel.signal); const args = run.mock.calls[0]?.[0] as string[] | undefined; expect(args).toContain("sherpa-onnx-node@1.13.8"); expect(args).toContain(sherpaPlatformPackage());