mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 05:31:47 +00:00
- Single-source registry: oauth clientId/tokenUrl, usage URLs, image/embed configs, search defaultModel, codex fixedPort, google token url derive. - Remove 29 unused OmniRoute providers (registry 100→71); media intact. - De-adhoc: codex literals → registry format/oauth flags; reasoningInject, image/embed openrouter headers + xai bodyFields config-driven. - Add REGISTRY_TEMPLATE.js + expand PROVIDER_DEFAULTS/schema JSDoc. - Baselines updated; PROVIDERS 62 + alias 90 byte-for-byte, golden snapshots. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
// OpenAI TTS — model format: "tts-model/voice"
|
|
import { Buffer } from "node:buffer";
|
|
import { PROVIDER_MEDIA } from "../../providers/index.js";
|
|
|
|
const DEFAULT_TTS_MODEL = PROVIDER_MEDIA["openai"]?.ttsConfig?.defaultModel;
|
|
|
|
export default {
|
|
async synthesize(text, model, credentials) {
|
|
if (!credentials?.apiKey) throw new Error("No OpenAI API key configured");
|
|
|
|
let ttsModel = DEFAULT_TTS_MODEL;
|
|
let voice = "alloy";
|
|
if (model && model.includes("/")) {
|
|
const parts = model.split("/");
|
|
if (parts.length === 2) [ttsModel, voice] = parts;
|
|
} else if (model) {
|
|
voice = model;
|
|
}
|
|
|
|
const baseUrl = (credentials.baseUrl || "https://api.openai.com").replace(/\/+$/, "");
|
|
const res = await fetch(`${baseUrl}/v1/audio/speech`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${credentials.apiKey}` },
|
|
body: JSON.stringify({ model: ttsModel, voice, input: text }),
|
|
});
|
|
if (!res.ok) {
|
|
const err = await res.json().catch(() => ({}));
|
|
throw new Error(err?.error?.message || `OpenAI TTS failed: ${res.status}`);
|
|
}
|
|
const buf = await res.arrayBuffer();
|
|
return { base64: Buffer.from(buf).toString("base64"), format: "mp3" };
|
|
},
|
|
};
|