

























@@ -332,6 +332,26 @@ describe("buildMinimaxSpeechProvider", () => {
332332await rm(tempStateDir, { recursive: true, force: true });
333333});
334334335+function firstFetchCall(): unknown[] {
336+const call = vi.mocked(globalThis.fetch).mock.calls.at(0);
337+if (!call) {
338+throw new Error("Expected MiniMax TTS fetch call");
339+}
340+return call as unknown[];
341+}
342+343+function firstFetchInit(): RequestInit | undefined {
344+return firstFetchCall().at(1) as RequestInit | undefined;
345+}
346+347+function firstFetchBody(): Record<string, unknown> {
348+const init = firstFetchInit();
349+if (typeof init?.body !== "string") {
350+throw new Error("Expected MiniMax TTS fetch init body");
351+}
352+return JSON.parse(init.body) as Record<string, unknown>;
353+}
354+335355it("makes correct API call and decodes hex response", async () => {
336356const hexAudio = Buffer.from("fake-audio-data").toString("hex");
337357const mockFetch = vi.mocked(globalThis.fetch);
@@ -356,15 +376,14 @@ describe("buildMinimaxSpeechProvider", () => {
356376expect(result.audioBuffer.toString()).toBe("fake-audio-data");
357377358378expect(mockFetch).toHaveBeenCalledOnce();
359-const [url, init] = mockFetch.mock.calls[0];
379+const url = firstFetchCall().at(0);
360380expect(url).toBe("https://api.minimaxi.com/v1/t2a_v2");
361-if (!init?.body) {
362-throw new Error("Expected MiniMax TTS fetch init body");
363-}
364-const body = JSON.parse(init.body as string);
381+const body = firstFetchBody();
365382expect(body.model).toBe("speech-2.8-hd");
366383expect(body.text).toBe("Hello world");
367-expect(body.voice_setting.voice_id).toBe("English_expressive_narrator");
384+expect((body.voice_setting as Record<string, unknown>).voice_id).toBe(
385+"English_expressive_narrator",
386+);
368387expect(transcodeAudioBufferToOpusMock).not.toHaveBeenCalled();
369388});
370389@@ -421,12 +440,13 @@ describe("buildMinimaxSpeechProvider", () => {
421440timeoutMs: 30000,
422441});
423442424-const body = JSON.parse(vi.mocked(globalThis.fetch).mock.calls[0][1]!.body as string);
443+const body = firstFetchBody();
425444expect(body.model).toBe("speech-01-240228");
426-expect(body.voice_setting.voice_id).toBe("custom_voice");
427-expect(body.voice_setting.speed).toBe(1.5);
428-expect(body.voice_setting.vol).toBe(1.5);
429-expect(body.voice_setting.pitch).toBe(0);
445+const voiceSetting = body.voice_setting as Record<string, unknown>;
446+expect(voiceSetting.voice_id).toBe("custom_voice");
447+expect(voiceSetting.speed).toBe(1.5);
448+expect(voiceSetting.vol).toBe(1.5);
449+expect(voiceSetting.pitch).toBe(0);
430450});
431451432452it("uses a MiniMax Token Plan env var when no API key is configured", async () => {
@@ -444,7 +464,7 @@ describe("buildMinimaxSpeechProvider", () => {
444464timeoutMs: 30000,
445465});
446466447-const [, init] = vi.mocked(globalThis.fetch).mock.calls[0];
467+const init = firstFetchInit();
448468expect(init?.headers).toEqual({
449469Authorization: "Bearer sk-cp-env",
450470"Content-Type": "application/json",
@@ -485,7 +505,8 @@ describe("buildMinimaxSpeechProvider", () => {
485505timeoutMs: 30000,
486506});
487507488-const [url, init] = vi.mocked(globalThis.fetch).mock.calls[0];
508+const url = firstFetchCall().at(0);
509+const init = firstFetchInit();
489510expect(url).toBe("https://api.minimaxi.com/v1/t2a_v2");
490511expect(init?.headers).toEqual({
491512Authorization: "Bearer portal-token",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。