TTS/STT languages and voices for each provider (#281)

* wip

* wip

* wip

* wip

* wip

* wip

* add testcase
This commit is contained in:
Hoan Luu Huu
2024-01-09 06:15:40 +07:00
committed by GitHub
parent 997ff05f3c
commit 7e046ac7f3
27 changed files with 11536 additions and 82 deletions
+191 -1
View File
@@ -8,6 +8,30 @@ const fs = require('fs');
const { AssemblyAI } = require('assemblyai');
const {decrypt, obscureKey} = require('./encrypt-decrypt');
const TtsGoogleLanguagesVoices = require('./speech-data/tts-google');
const TtsAwsLanguagesVoices = require('./speech-data/tts-aws');
const TtsMicrosoftLanguagesVoices = require('./speech-data/tts-microsoft');
const TtsWellsaidLanguagesVoices = require('./speech-data/tts-wellsaid');
const TtsNuanceLanguagesVoices = require('./speech-data/tts-nuance');
const TtsIbmLanguagesVoices = require('./speech-data/tts-ibm');
const TtsNvidiaLanguagesVoices = require('./speech-data/tts-nvidia');
const TtsElevenlabsLanguagesVoices = require('./speech-data/tts-elevenlabs');
const TtsWhisperLanguagesVoices = require('./speech-data/tts-whisper');
const TtsModelDeepgram = require('./speech-data/tts-model-deepgram');
const TtsModelElevenLabs = require('./speech-data/tts-model-elevenlabs');
const TtsModelWhisper = require('./speech-data/tts-model-whisper');
const SttGoogleLanguagesVoices = require('./speech-data/stt-google');
const SttAwsLanguagesVoices = require('./speech-data/stt-aws');
const SttMicrosoftLanguagesVoices = require('./speech-data/stt-microsoft');
const SttNuanceLanguagesVoices = require('./speech-data/stt-nuance');
const SttDeepgramLanguagesVoices = require('./speech-data/stt-deepgram');
const SttIbmLanguagesVoices = require('./speech-data/stt-ibm');
const SttNvidiaLanguagesVoices = require('./speech-data/stt-nvidia');
const SttCobaltLanguagesVoices = require('./speech-data/stt-cobalt');
const SttSonioxLanguagesVoices = require('./speech-data/stt-soniox');
const SttAssemblyaiLanguagesVoices = require('./speech-data/stt-assemblyai');
const testSonioxStt = async(logger, credentials) => {
const api_key = credentials;
@@ -419,6 +443,171 @@ function decryptCredential(obj, credential, logger, isObscureKey = true) {
}
}
/**
*
* @param {*} logger logger
* @param {*} vendor vendor
* @param {*} credential STT/TTS vendor credential, can be null
* @returns List of language and coresponding voices for specific vendor follow below format
* {
"tts": [
{
code: "ar-XA",
name: "Arabic",
voices: [
{ value: "ar-XA-Standard-A", name: "Standard-A (Female)" },
]
}
],
"stt": [
{ name: "Afrikaans (South Africa)", code: "af-ZA" },
]
}
*/
async function getLanguagesAndVoicesForVendor(logger, vendor, credential) {
switch (vendor) {
case 'google':
return await getLanguagesVoicesForGoogle(credential);
case 'aws':
return await getLanguagesVoicesForAws(credential);
case 'microsoft':
return await getLanguagesVoicesForMicrosoft(credential);
case 'wellsaid':
return await getLanguagesVoicesForWellsaid(credential);
case 'nuance':
return await getLanguagesVoicesForNuane(credential);
case 'deepgram':
return await getLanguagesVoicesForDeepgram(credential);
case 'ibm':
return await getLanguagesVoicesForIbm(credential);
case 'nvidia':
return await getLanguagesVoicesForNvida(credential);
case 'cobalt':
return await getLanguagesVoicesForCobalt(credential);
case 'soniox':
return await getLanguagesVoicesForSoniox(credential);
case 'elevenlabs':
return await getLanguagesVoicesForElevenlabs(credential);
case 'assemblyai':
return await getLanguagesVoicesForAssemblyAI(credential);
case 'whisper':
return await getLanguagesVoicesForWhisper(credential);
default:
logger.info(`invalid vendor ${vendor}, return empty result`);
throw new Error(`Invalid vendor ${vendor}`);
}
}
async function getLanguagesVoicesForGoogle(credential) {
return tranform(TtsGoogleLanguagesVoices, SttGoogleLanguagesVoices);
}
async function getLanguagesVoicesForAws(credential) {
return tranform(TtsAwsLanguagesVoices, SttAwsLanguagesVoices);
}
async function getLanguagesVoicesForMicrosoft(credential) {
return tranform(TtsMicrosoftLanguagesVoices, SttMicrosoftLanguagesVoices);
}
async function getLanguagesVoicesForWellsaid(credential) {
return tranform(TtsWellsaidLanguagesVoices);
}
async function getLanguagesVoicesForNuane(credential) {
return tranform(TtsNuanceLanguagesVoices, SttNuanceLanguagesVoices);
}
async function getLanguagesVoicesForDeepgram(credential) {
return tranform(undefined, SttDeepgramLanguagesVoices, TtsModelDeepgram);
}
async function getLanguagesVoicesForIbm(credential) {
return tranform(TtsIbmLanguagesVoices, SttIbmLanguagesVoices);
}
async function getLanguagesVoicesForNvida(credential) {
return tranform(TtsNvidiaLanguagesVoices, SttNvidiaLanguagesVoices);
}
async function getLanguagesVoicesForCobalt(credential) {
return tranform(undefined, SttCobaltLanguagesVoices);
}
async function getLanguagesVoicesForSoniox(credential) {
if (credential) {
} else {
return tranform(undefined, SttSonioxLanguagesVoices);
}
}
async function getLanguagesVoicesForElevenlabs(credential) {
if (credential) {
const get = bent('https://api.elevenlabs.io', 'GET', 'json', {
'xi-api-key' : credential.api_key
});
const [langResp, voiceResp] = await Promise.all([get('/v1/models'), get('/v1/voices')]);
const model = langResp.find((m) => m.model_id === credential.model_id);
const languages = model ? model.languages.map((l) => {
return {
value: l.language_id,
name: l.name
};
}).sort((a, b) => a.name.localeCompare(b.name)) : [];
if (languages && languages.length > 0) {
const voices = voiceResp ? voiceResp.voices.map((v) => {
let name = `${v.name}${v.category !== 'premade' ? ` (${v.category})` : ''} -
${v.labels.accent ? ` ${v.labels.accent},` : ''}
${v.labels.description ? ` ${v.labels.description},` : ''}
${v.labels.age ? ` ${v.labels.age},` : ''}
${v.labels.gender ? ` ${v.labels.gender},` : ''}
${v.labels['use case'] ? ` ${v.labels['use case']},` : ''}
`;
const lastIndex = name.lastIndexOf(',');
if (lastIndex !== -1) {
name = name.substring(0, lastIndex);
}
return {
value: v.voice_id,
name
};
}).sort((a, b) => a.name.localeCompare(b.name)) : [];
languages[0].voices = voices;
}
return tranform(languages, undefined, TtsModelElevenLabs);
} else {
return tranform(TtsElevenlabsLanguagesVoices, undefined, TtsModelElevenLabs);
}
}
async function getLanguagesVoicesForAssemblyAI(credential) {
if (credential) {
} else {
return tranform(undefined, SttAssemblyaiLanguagesVoices);
}
}
async function getLanguagesVoicesForWhisper(credential) {
if (credential) {
} else {
return tranform(TtsWhisperLanguagesVoices, undefined, TtsModelWhisper);
}
}
function tranform(tts, stt, models) {
return {
...(tts && {tts}),
...(stt && {stt}),
...(models && {models})
};
}
module.exports = {
testGoogleTts,
testGoogleStt,
@@ -439,5 +628,6 @@ module.exports = {
testDeepgramTTS,
getSpeechCredential,
decryptCredential,
testWhisper
testWhisper,
getLanguagesAndVoicesForVendor
};