support assembly ai (#248)

* support assembly ai

* wip

* wip
This commit is contained in:
Hoan Luu Huu
2023-11-01 08:02:32 -04:00
committed by GitHub
parent 30ba84d57b
commit f15c339a2a
5 changed files with 90 additions and 2 deletions
+22 -1
View File
@@ -20,7 +20,8 @@ const {
testSonioxStt,
testIbmTts,
testIbmStt,
testElevenlabs
testElevenlabs,
testAssemblyStt
} = require('../../utils/speech-utils');
const bent = require('bent');
const {promisePool} = require('../../db');
@@ -211,6 +212,11 @@ const encryptCredential = (obj) => {
const elevenlabsData = JSON.stringify({api_key, model_id});
return encrypt(elevenlabsData);
case 'assemblyai':
assert(api_key, 'invalid assemblyai speech credential: api_key is required');
const assemblyaiData = JSON.stringify({api_key});
return encrypt(assemblyaiData);
default:
if (vendor.startsWith('custom:')) {
const customData = JSON.stringify({auth_token, custom_stt_url, custom_tts_url});
@@ -335,6 +341,9 @@ function decryptCredential(obj, credential, logger) {
obj.auth_token = obscureKey(o.auth_token);
obj.custom_stt_url = o.custom_stt_url;
obj.custom_tts_url = o.custom_tts_url;
} else if ('assemblyai' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
obj.api_key = obscureKey(o.api_key);
}
}
@@ -757,6 +766,18 @@ router.get('/:sid/test', async(req, res) => {
SpeechCredential.ttsTestResult(sid, false);
}
}
} else if (cred.vendor === 'assemblyai') {
const {api_key} = credential;
if (cred.use_for_stt) {
try {
await testAssemblyStt(logger, {api_key});
results.stt.status = 'ok';
SpeechCredential.sttTestResult(sid, true);
} catch (err) {
results.stt = {status: 'fail', reason: err.message};
SpeechCredential.sttTestResult(sid, false);
}
}
}
res.status(200).json(results);