From 5c687aebddc3962d82721bc2db97bb060cbb0b9e Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 2 Mar 2023 14:04:03 -0500 Subject: [PATCH] add support for custom speech api --- lib/routes/api/speech-credentials.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/routes/api/speech-credentials.js b/lib/routes/api/speech-credentials.js index 615d204..2e5f1e9 100644 --- a/lib/routes/api/speech-credentials.js +++ b/lib/routes/api/speech-credentials.js @@ -53,7 +53,8 @@ const encryptCredential = (obj) => { stt_api_key, stt_region, riva_server_uri, - instance_id + instance_id, + auth_token = '' } = obj; switch (vendor) { @@ -119,7 +120,11 @@ const encryptCredential = (obj) => { return encrypt(sonioxData); default: - assert(false, `invalid or missing vendor: ${vendor}`); + if (vendor.startsWith('custom:')) { + const customData = JSON.stringify({auth_token}); + return encrypt(customData); + } + else assert(false, `invalid or missing vendor: ${vendor}`); } }; @@ -230,6 +235,10 @@ router.get('/', async(req, res) => { const o = JSON.parse(decrypt(credential)); obj.api_key = obscureKey(o.api_key); } + else if (obj.vendor.startsWith('custom:')) { + const o = JSON.parse(decrypt(credential)); + return {...obj, ...o}; + } return obj; })); } catch (err) { @@ -295,6 +304,10 @@ router.get('/:sid', async(req, res) => { const o = JSON.parse(decrypt(credential)); obj.riva_server_uri = o.riva_server_uri; } + else if (obj.vendor.startsWith('custom:')) { + const o = JSON.parse(decrypt(credential)); + obj.auth_token = obscureKey(o.auth_token); + } res.status(200).json(obj); } catch (err) { sysError(logger, res, err); @@ -592,7 +605,8 @@ router.get('/:sid/test', async(req, res) => { SpeechCredential.sttTestResult(sid, false); } } - } else if (cred.vendor === 'soniox') { + } + else if (cred.vendor === 'soniox') { const {api_key} = credential; if (cred.use_for_stt) { try { @@ -607,6 +621,7 @@ router.get('/:sid/test', async(req, res) => { } res.status(200).json(results); + } catch (err) { sysError(logger, res, err); }