Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.4 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";

const { normalizeSpeechResponseFormat, handleAudioSpeech } = await import(
  "../../open-sse/handlers/audioSpeech.ts"
);

test("normalizeSpeechResponseFormat aliases ogg to opus (#10587)", () => {
  assert.equal(normalizeSpeechResponseFormat("ogg"), "opus");
  assert.equal(normalizeSpeechResponseFormat("OGG"), "opus");
  assert.equal(normalizeSpeechResponseFormat("opus"), "opus");
  assert.equal(normalizeSpeechResponseFormat("mp3"), "mp3");
  assert.equal(normalizeSpeechResponseFormat(undefined), "mp3");
});

test("OpenAI-compat speech path remaps ogg to opus before upstream", async () => {
  const originalFetch = globalThis.fetch;
  let captured;
  globalThis.fetch = async (_url, options = {}) => {
    captured = JSON.parse(String(options.body || "{}"));
    return new Response(new Uint8Array([1, 2, 3]), {
      status: 200,
      headers: { "content-type": "audio/opus" },
    });
  };
  try {
    const response = await handleAudioSpeech({
      body: {
        model: "openai/tts-1",
        input: "format check",
        voice: "alloy",
        response_format: "ogg",
      },
      credentials: { apiKey: "openai-key" },
    });
    assert.equal(response.status, 200);
    assert.equal(captured.response_format, "opus");
    assert.equal(captured.model, "tts-1");
  } finally {
    globalThis.fetch = originalFetch;
  }
});