check playht can fetch voices when adding new speech credential (#309)

* check playht can fetch voices when adding new speech credential

* wip

* wip

* wip

* wip
This commit is contained in:
Hoan Luu Huu
2024-04-12 18:01:13 +07:00
committed by GitHub
parent b21d10eb3e
commit 80418aa7e5
2 changed files with 23 additions and 3 deletions

View File

@@ -743,7 +743,12 @@ router.get('/:sid/test', async(req, res) => {
results.tts.status = 'ok';
SpeechCredential.ttsTestResult(sid, true);
} catch (err) {
results.tts = {status: 'fail', reason: err.message};
let reason = err.message;
// if error is from bent, let get the body
try {
reason = await err.text();
} catch {}
results.tts = {status: 'fail', reason};
SpeechCredential.ttsTestResult(sid, false);
}
}

View File

@@ -256,6 +256,8 @@ const testPlayHT = async(logger, synthAudio, credentials) => {
text: 'Hi there and welcome to jambones!'
}
);
// Test if playHT can fetch voices
await fetchLayHTVoices(credentials);
} catch (err) {
logger.info({err}, 'synth Playht returned error');
throw err;
@@ -679,7 +681,7 @@ const concat = (a) => {
return a ? ` ${a},` : '';
};
async function getLanguagesVoicesForPlayHT(credential) {
const fetchLayHTVoices = async(credential) => {
if (credential) {
const get = bent('https://api.play.ht', 'GET', 'json', {
'AUTHORIZATION' : credential.api_key,
@@ -687,7 +689,20 @@ async function getLanguagesVoicesForPlayHT(credential) {
'Accept': 'application/json'
});
const [cloned_voice, voices] = await Promise.all([ get('/api/v2/cloned-voices'), get('/api/v2/voices')]);
const voices = await get('/api/v2/voices');
let clone_voices = [];
try {
// try if the account has permission to cloned voice
//otherwise ignore this.
clone_voices = await get('/api/v2/cloned-voices');
} catch {}
return [clone_voices, voices];
}
};
async function getLanguagesVoicesForPlayHT(credential) {
if (credential) {
const [cloned_voice, voices] = await fetchLayHTVoices(credential);
const list_voices = [...cloned_voice, ...voices];
const buildVoice = (d) => {