diff --git a/lib/utils/speech-utils.js b/lib/utils/speech-utils.js index 325aa15..3557cae 100644 --- a/lib/utils/speech-utils.js +++ b/lib/utils/speech-utils.js @@ -257,13 +257,7 @@ const testPlayHT = async(logger, synthAudio, credentials) => { } ); // Test if playHT can fetch voices - const get = bent('https://api.play.ht', 'GET', 'json', { - 'AUTHORIZATION' : credentials.api_key, - 'X-USER-ID': credentials.user_id, - 'Accept': 'application/json' - }); - - await Promise.all([ get('/api/v2/cloned-voices'), get('/api/v2/voices')]); + await fetchLayHTVoices(credentials); } catch (err) { logger.info({err}, 'synth Playht returned error'); throw err; @@ -687,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, @@ -695,7 +689,13 @@ async function getLanguagesVoicesForPlayHT(credential) { 'Accept': 'application/json' }); - const [cloned_voice, voices] = await Promise.all([ get('/api/v2/cloned-voices'), get('/api/v2/voices')]); + return await Promise.all([ get('/api/v2/cloned-voices'), get('/api/v2/voices')]); + } +}; + +async function getLanguagesVoicesForPlayHT(credential) { + if (credential) { + const [cloned_voice, voices] = await fetchLayHTVoices(credential); const list_voices = [...cloned_voice, ...voices]; const buildVoice = (d) => {