Fix voices API parsing - use correct data.data format with model.voices arrays
This commit is contained in:
parent
7a658f7bdf
commit
d1749209a0
1 changed files with 15 additions and 17 deletions
|
|
@ -371,34 +371,32 @@ async function openUncloseaiEmbeddedModalNew() {
|
|||
}
|
||||
|
||||
const data = await response.json();
|
||||
const voices = data.voices || [];
|
||||
const models = data.data || [];
|
||||
|
||||
if (voices.length === 0) {
|
||||
throw new Error("No voices in API response");
|
||||
if (models.length === 0) {
|
||||
throw new Error("No models 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);
|
||||
});
|
||||
// Count total voices across all models
|
||||
loadedVoicesCount = models.reduce((sum, model) => sum + (model.voices?.length || 0), 0);
|
||||
|
||||
// Add options grouped by model
|
||||
Object.keys(groupedVoices).sort().forEach(model => {
|
||||
models.forEach(model => {
|
||||
const voices = model.voices || [];
|
||||
if (voices.length === 0) return;
|
||||
|
||||
const optgroup = document.createElement("optgroup");
|
||||
optgroup.label = model;
|
||||
groupedVoices[model].forEach(voice => {
|
||||
optgroup.label = model.id;
|
||||
|
||||
voices.forEach(voice => {
|
||||
const option = document.createElement("option");
|
||||
option.value = `${model}:${voice}`; // Store model:voice format
|
||||
option.value = `${model.id}:${voice}`; // Store model:voice format
|
||||
option.textContent = voice.charAt(0).toUpperCase() + voice.slice(1);
|
||||
optgroup.appendChild(option);
|
||||
});
|
||||
|
||||
voiceSelect.appendChild(optgroup);
|
||||
});
|
||||
|
||||
|
|
@ -408,7 +406,7 @@ async function openUncloseaiEmbeddedModalNew() {
|
|||
voiceSelect.value = savedVoice;
|
||||
}
|
||||
|
||||
console.log("Voices loaded:", voices.length, "voices from API");
|
||||
console.log("Voices loaded:", loadedVoicesCount, "voices from", models.length, "models");
|
||||
};
|
||||
|
||||
// Save voice selection to localStorage when changed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue