fixed deepgram cannot fetch list of available voices for model (#500)

This commit is contained in:
Hoan Luu Huu
2025-09-27 21:13:06 +07:00
committed by GitHub
parent a15c5cd267
commit 9421bb8aa1
2 changed files with 145 additions and 36 deletions

View File

@@ -935,8 +935,30 @@ async function getLanguagesVoicesForDeepgram(credential, getTtsVoices, logger) {
logger.error({response}, 'Error fetching Deepgram voices');
throw new Error('failed to list voices');
}
const {stt, tts} = await response.json();
let sttLangs = SttDeepgramLanguagesVoices;
const {stt, tts, languages} = await response.json();
// Helper function to get language name
const getLanguageName = (langCode) => {
if (languages && languages[langCode]) {
return languages[langCode];
}
const existingLang = SttDeepgramLanguagesVoices.find((l) => l.value === langCode);
return existingLang ? existingLang.name : capitalizeFirst(langCode);
};
// Collect unique languages from selected models
const allSttLanguages = new Set();
const modelsToProcess = model_id ?
stt.filter((m) => m.canonical_name === model_id) :
stt;
modelsToProcess.forEach((model) => {
if (model.languages && Array.isArray(model.languages)) {
model.languages.forEach((lang) => allSttLanguages.add(lang));
}
});
// Convert to expected format
const sttLangs = Array.from(allSttLanguages).map((langCode) => ({
name: getLanguageName(langCode),
value: langCode
})).sort((a, b) => a.name.localeCompare(b.name));
const sttModels = Array.from(
new Map(
stt.map((m) => [m.canonical_name, { name: capitalizeFirst(m.canonical_name), value: m.canonical_name }])
@@ -947,16 +969,6 @@ async function getLanguagesVoicesForDeepgram(credential, getTtsVoices, logger) {
tts.map((m) => [m.canonical_name, { name: capitalizeFirst(m.canonical_name), value: m.canonical_name }])
).values()
).sort((a, b) => a.name.localeCompare(b.name));
// if model_id is not provided, return all models, all voices, all languages
if (!model_id) {
return tranform(TtsLanguagesDeepgram, sttLangs, ttsModels, sttModels);
}
const selectedSttModel = stt.find((m) => m.canonical_name === model_id);
const selectedSttLangs = selectedSttModel ? selectedSttModel.languages : [];
sttLangs = SttDeepgramLanguagesVoices.filter((l) => {
return selectedSttLangs.includes(l.value);
});
return tranform(TtsLanguagesDeepgram, sttLangs, ttsModels, sttModels);
}
}