From 7a658f7bdfacaa8ba481e4ad9defde7001b4f626 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 10 Nov 2025 05:48:18 -0500 Subject: [PATCH] Remove fallback voices - fail properly if API doesn't respond --- public/src/uncloseai-embed-modal.js | 102 ++++++++++++---------------- 1 file changed, 43 insertions(+), 59 deletions(-) diff --git a/public/src/uncloseai-embed-modal.js b/public/src/uncloseai-embed-modal.js index e5fd9d3..ec30f38 100644 --- a/public/src/uncloseai-embed-modal.js +++ b/public/src/uncloseai-embed-modal.js @@ -363,68 +363,52 @@ async function openUncloseaiEmbeddedModalNew() { // Load voices dynamically from API const loadVoices = async () => { - try { - const { VOICES_API_URL } = await import("./config.js"); - const response = await fetch(VOICES_API_URL); + const { VOICES_API_URL } = await import("./config.js"); + const response = await fetch(VOICES_API_URL); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - const data = await response.json(); - const voices = data.voices || []; - - voiceSelect.innerHTML = ''; // Clear existing options - - if (voices.length > 0) { - loadedVoicesCount = voices.length; - - // Group voices by model - const groupedVoices = {}; - voices.forEach(v => { - if (!groupedVoices[v.model]) { - groupedVoices[v.model] = []; - } - groupedVoices[v.model].push(v.voice); - }); - - // Add options grouped by model - Object.keys(groupedVoices).sort().forEach(model => { - const optgroup = document.createElement("optgroup"); - optgroup.label = model; - groupedVoices[model].forEach(voice => { - const option = document.createElement("option"); - option.value = `${model}:${voice}`; // Store model:voice format - option.textContent = voice.charAt(0).toUpperCase() + voice.slice(1); - optgroup.appendChild(option); - }); - voiceSelect.appendChild(optgroup); - }); - - console.log("Voices loaded:", voices.length, "voices from API"); - } else { - // No voices from API, use fallback - throw new Error("No voices in API response"); - } - } catch (error) { - console.warn("Failed to load voices from API, using fallback:", error); - // Fallback to default voices with model prefix - const fallbackVoices = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]; - loadedVoicesCount = fallbackVoices.length; - voiceSelect.innerHTML = ''; - fallbackVoices.forEach((voice) => { - const option = document.createElement("option"); - option.value = `tts-1:${voice}`; // Store model:voice format - option.textContent = voice.charAt(0).toUpperCase() + voice.slice(1); - voiceSelect.appendChild(option); - }); - console.log("Voices loaded:", fallbackVoices.length, "fallback voices"); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); } - // Load saved voice from localStorage or default to tts-1:alloy - const savedVoice = localStorage.getItem("selectedVoice") || "tts-1:alloy"; - voiceSelect.value = savedVoice; - console.log("Selected voice:", savedVoice); + const data = await response.json(); + const voices = data.voices || []; + + if (voices.length === 0) { + throw new Error("No voices in API response"); + } + + voiceSelect.innerHTML = ''; // Clear existing options + loadedVoicesCount = voices.length; + + // Group voices by model + const groupedVoices = {}; + voices.forEach(v => { + if (!groupedVoices[v.model]) { + groupedVoices[v.model] = []; + } + groupedVoices[v.model].push(v.voice); + }); + + // Add options grouped by model + Object.keys(groupedVoices).sort().forEach(model => { + const optgroup = document.createElement("optgroup"); + optgroup.label = model; + groupedVoices[model].forEach(voice => { + const option = document.createElement("option"); + option.value = `${model}:${voice}`; // Store model:voice format + option.textContent = voice.charAt(0).toUpperCase() + voice.slice(1); + optgroup.appendChild(option); + }); + voiceSelect.appendChild(optgroup); + }); + + // Load saved voice from localStorage or default to first voice + const savedVoice = localStorage.getItem("selectedVoice"); + if (savedVoice && voiceSelect.querySelector(`option[value="${savedVoice}"]`)) { + voiceSelect.value = savedVoice; + } + + console.log("Voices loaded:", voices.length, "voices from API"); }; // Save voice selection to localStorage when changed