mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
fixed deepgram cannot fetch list of available voices for model (#500)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user