

























@@ -6,6 +6,7 @@ import type { MsgContext } from "../auto-reply/templating.js";
66import type { OpenClawConfig } from "../config/types.js";
77import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
88import { withEnvAsync } from "../test-utils/env.js";
9+import { CLI_OUTPUT_MAX_BUFFER } from "./defaults.constants.js";
910import { createSafeAudioFixtureBuffer } from "./runner.test-utils.js";
1011import type { MediaUnderstandingProvider } from "./types.js";
1112@@ -106,6 +107,29 @@ function expectTranscriptApplied(params: {
106107expect(params.ctx.BodyForCommands).toBe(params.commandBody);
107108}
108109110+function getRunExecCall(index = 0) {
111+const call = mockedRunExec.mock.calls[index];
112+if (!call) {
113+throw new Error(`expected runExec call ${index}`);
114+}
115+return call;
116+}
117+118+function getRunFfmpegArgs(index = 0) {
119+const [args] = mockedRunFfmpeg.mock.calls[index] ?? [];
120+if (!Array.isArray(args)) {
121+throw new Error(`expected runFfmpeg args ${index}`);
122+}
123+return args;
124+}
125+126+function expectCliRunOptions(options: unknown) {
127+expect(options).toEqual({
128+timeoutMs: 60_000,
129+maxBuffer: CLI_OUTPUT_MAX_BUFFER,
130+});
131+}
132+109133function createMediaDisabledConfig(): OpenClawConfig {
110134return {
111135tools: {
@@ -735,11 +759,16 @@ describe("applyMediaUnderstanding", () => {
735759);
736760737761expect(ctx.Transcript).toBe("sherpa ok");
738-expect(mockedRunExec).toHaveBeenCalledWith(
739-"sherpa-onnx-offline",
740-expect.any(Array),
741-expect.any(Object),
742-);
762+const [command, args, options] = getRunExecCall();
763+expect(command).toBe("sherpa-onnx-offline");
764+expect(args).toEqual([
765+`--tokens=${path.join(modelDir, "tokens.txt")}`,
766+`--encoder=${path.join(modelDir, "encoder.onnx")}`,
767+`--decoder=${path.join(modelDir, "decoder.onnx")}`,
768+`--joiner=${path.join(modelDir, "joiner.onnx")}`,
769+await fs.realpath(ctx.MediaPath ?? ""),
770+]);
771+expectCliRunOptions(options);
743772});
744773745774it("auto-detects whisper-cli when sherpa is unavailable", async () => {
@@ -764,11 +793,16 @@ describe("applyMediaUnderstanding", () => {
764793);
765794766795expect(ctx.Transcript).toBe("whisper cpp ok");
767-expect(mockedRunExec).toHaveBeenCalledWith(
768-"whisper-cli",
769-expect.any(Array),
770-expect.any(Object),
771-);
796+const [command, args, options] = getRunExecCall();
797+expect(command).toBe("whisper-cli");
798+if (!Array.isArray(args)) {
799+throw new Error("expected whisper-cli args");
800+}
801+expect(args.slice(0, 4)).toEqual(["-m", modelPath, "-otxt", "-of"]);
802+expect(typeof args[4]).toBe("string");
803+expect(String(args[4]).endsWith("sample")).toBe(true);
804+expect(args.slice(5)).toEqual(["-np", "-nt", await fs.realpath(ctx.MediaPath ?? "")]);
805+expectCliRunOptions(options);
772806});
773807774808it("transcodes non-wav audio before auto-detected whisper-cli runs", async () => {
@@ -811,24 +845,23 @@ describe("applyMediaUnderstanding", () => {
811845);
812846813847expect(ctx.Transcript).toBe("whisper cpp ogg ok");
814-expect(mockedRunFfmpeg).toHaveBeenCalledWith(
815-expect.arrayContaining([
816-"-i",
817-expect.stringMatching(/telegram-voice\.ogg$/),
818-"-ac",
819-"1",
820-"-ar",
821-"16000",
822-"-c:a",
823-"pcm_s16le",
824-expect.stringMatching(/telegram-voice\.wav.*\.part$/),
825-]),
826-);
827-expect(mockedRunExec).toHaveBeenCalledWith(
828-"whisper-cli",
829-expect.arrayContaining([expect.stringMatching(/telegram-voice\.wav$/)]),
830-expect.any(Object),
831-);
848+const ffmpegArgs = getRunFfmpegArgs();
849+expect(ffmpegArgs).toHaveLength(10);
850+expect(ffmpegArgs.slice(0, 2)).toEqual(["-y", "-i"]);
851+expect(String(ffmpegArgs[2]).endsWith("telegram-voice.ogg")).toBe(true);
852+expect(ffmpegArgs.slice(3, 9)).toEqual(["-ac", "1", "-ar", "16000", "-c:a", "pcm_s16le"]);
853+expect(String(ffmpegArgs[9]).includes("telegram-voice.wav")).toBe(true);
854+expect(String(ffmpegArgs[9]).endsWith(".part")).toBe(true);
855+856+const [command, args, options] = getRunExecCall();
857+expect(command).toBe("whisper-cli");
858+if (!Array.isArray(args)) {
859+throw new Error("expected whisper-cli transcode args");
860+}
861+expect(args.slice(0, 4)).toEqual(["-m", modelPath, "-otxt", "-of"]);
862+expect(args.slice(5, 7)).toEqual(["-np", "-nt"]);
863+expect(String(args[7]).endsWith("telegram-voice.wav")).toBe(true);
864+expectCliRunOptions(options);
832865});
833866834867it("skips audio auto-detect when no supported binaries or provider keys are available", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。