File size: 5,683 Bytes
88c4c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | import { GOOGLE_TTS_LANGUAGES } from "./googleTtsLanguages.js";
// ββ Voice definitions (DRY β reused across providers) ββββββββββββββββββββββ
const VOICES = {
alloy: { id: "alloy", name: "Alloy" },
ash: { id: "ash", name: "Ash" },
ballad: { id: "ballad", name: "Ballad" },
cedar: { id: "cedar", name: "Cedar" },
coral: { id: "coral", name: "Coral" },
echo: { id: "echo", name: "Echo" },
fable: { id: "fable", name: "Fable" },
marin: { id: "marin", name: "Marin" },
nova: { id: "nova", name: "Nova" },
onyx: { id: "onyx", name: "Onyx" },
sage: { id: "sage", name: "Sage" },
shimmer: { id: "shimmer", name: "Shimmer" },
verse: { id: "verse", name: "Verse" },
};
const v = (...keys) => keys.map((k) => ({ ...VOICES[k], type: "tts" }));
// 9 voices for tts-1 / tts-1-hd
const VOICES_STANDARD = v("alloy", "ash", "coral", "echo", "fable", "nova", "onyx", "sage", "shimmer");
// 13 voices for gpt-4o-mini-tts
const VOICES_FULL = v("alloy", "ash", "ballad", "cedar", "coral", "echo", "fable", "marin", "nova", "onyx", "sage", "shimmer", "verse");
// Gemini prebuilt voices (30 voices, multi-language auto-detect)
const GEMINI_VOICES = [
"Zephyr", "Puck", "Charon", "Kore", "Fenrir", "Leda", "Orus", "Aoede",
"Callirrhoe", "Autonoe", "Enceladus", "Iapetus", "Umbriel", "Algieba",
"Despina", "Erinome", "Algenib", "Rasalgethi", "Laomedeia", "Achernar",
"Alnilam", "Schedar", "Gacrux", "Pulcherrima", "Achird", "Zubenelgenubi",
"Vindemiatrix", "Sadachbia", "Sadaltager", "Sulafat",
].map((id) => ({ id, name: id, type: "tts" }));
// ββ TTS Config (config-driven, single source of truth) βββββββββββββββββββββ
export const TTS_MODELS_CONFIG = {
openai: {
models: [
{ id: "gpt-4o-mini-tts", name: "GPT-4o Mini TTS", type: "tts" },
{ id: "tts-1-hd", name: "TTS-1 HD", type: "tts" },
{ id: "tts-1", name: "TTS-1", type: "tts" },
],
voices: {
"gpt-4o-mini-tts": VOICES_FULL,
"tts-1": VOICES_STANDARD,
"tts-1-hd": VOICES_STANDARD,
},
// Flat voice list (all unique voices) for backward compat
allVoices: VOICES_FULL,
},
openrouter: {
models: [
{ id: "openai/gpt-4o-mini-tts", name: "GPT-4o Mini TTS", type: "tts" },
{ id: "openai/tts-1-hd", name: "TTS-1 HD", type: "tts" },
{ id: "openai/tts-1", name: "TTS-1", type: "tts" },
],
voices: {
"openai/gpt-4o-mini-tts": VOICES_FULL,
"openai/tts-1": VOICES_STANDARD,
"openai/tts-1-hd": VOICES_STANDARD,
},
allVoices: VOICES_FULL,
},
elevenlabs: {
models: [
{ id: "eleven_flash_v2_5", name: "Flash v2.5 (Fastest)", type: "tts" },
{ id: "eleven_turbo_v2_5", name: "Turbo v2.5 (Fast)", type: "tts" },
{ id: "eleven_multilingual_v2", name: "Multilingual v2 (Quality)", type: "tts" },
{ id: "eleven_monolingual_v1", name: "Monolingual v1 (English)", type: "tts" },
],
// voices come from API, not hardcoded
},
"edge-tts": {
defaults: [
{ id: "en-US-AriaNeural", name: "Aria (en-US)", type: "tts" },
{ id: "en-US-GuyNeural", name: "Guy (en-US)", type: "tts" },
{ id: "en-GB-SoniaNeural", name: "Sonia (en-GB)", type: "tts" },
{ id: "vi-VN-HoaiMyNeural", name: "Hoai My (vi-VN)", type: "tts" },
{ id: "vi-VN-NamMinhNeural", name: "Nam Minh (vi-VN)", type: "tts" },
{ id: "zh-CN-XiaoxiaoNeural", name: "Xiaoxiao (zh-CN)", type: "tts" },
{ id: "zh-CN-YunxiNeural", name: "Yunxi (zh-CN)", type: "tts" },
{ id: "fr-FR-DeniseNeural", name: "Denise (fr-FR)", type: "tts" },
{ id: "de-DE-KatjaNeural", name: "Katja (de-DE)", type: "tts" },
{ id: "ja-JP-NanamiNeural", name: "Nanami (ja-JP)", type: "tts" },
{ id: "ko-KR-SunHiNeural", name: "SunHi (ko-KR)", type: "tts" },
],
},
"local-device": {
defaults: [
{ id: "default", name: "System Default Voice", type: "tts" },
],
},
"google-tts": {
defaults: GOOGLE_TTS_LANGUAGES,
},
gemini: {
models: [
{ id: "gemini-2.5-flash-preview-tts", name: "Gemini 2.5 Flash TTS", type: "tts" },
{ id: "gemini-2.5-pro-preview-tts", name: "Gemini 2.5 Pro TTS", type: "tts" },
],
voices: {
"gemini-2.5-flash-preview-tts": GEMINI_VOICES,
"gemini-2.5-pro-preview-tts": GEMINI_VOICES,
},
allVoices: GEMINI_VOICES,
},
};
// ββ Helper: get voices for a specific model ββββββββββββββββββββββββββββββββ
export function getTtsVoicesForModel(provider, modelId) {
const cfg = TTS_MODELS_CONFIG[provider];
if (!cfg?.voices) return null;
return cfg.voices[modelId] || cfg.allVoices || null;
}
// ββ Build flat entries for PROVIDER_MODELS backward compat βββββββββββββββββ
export function buildTtsProviderModels() {
const entries = {};
for (const [provider, cfg] of Object.entries(TTS_MODELS_CONFIG)) {
if (cfg.models) entries[`${provider}-tts-models`] = cfg.models;
if (cfg.allVoices) entries[`${provider}-tts-voices`] = cfg.allVoices;
if (cfg.defaults) entries[provider] = cfg.defaults;
}
// Keep openai-tts-voices key pointing to full voice list for backward compat
entries["openai-tts-voices"] = TTS_MODELS_CONFIG.openai.allVoices;
entries["openrouter-tts-voices"] = TTS_MODELS_CONFIG.openrouter.allVoices;
return entries;
}
|