From 613b801ba9ddde6e7fe86a10f549187c6f550a25 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Tue, 27 Sep 2022 09:32:30 +0100 Subject: [PATCH] add support for azure custom endpoints --- lib/routes/api/speech-credentials.js | 36 +++++++++++++++++++++++++--- lib/utils/speech-utils.js | 8 +++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/routes/api/speech-credentials.js b/lib/routes/api/speech-credentials.js index 1ae84a6..1d33e69 100644 --- a/lib/routes/api/speech-credentials.js +++ b/lib/routes/api/speech-credentials.js @@ -234,7 +234,7 @@ router.put('/:sid', async(req, res) => { const sid = req.params.sid; const logger = req.app.locals.logger; try { - const {use_for_tts, use_for_stt} = req.body; + const {use_for_tts, use_for_stt, region, aws_region} = req.body; if (typeof use_for_tts === 'undefined' && typeof use_for_stt === 'undefined') { throw new DbErrorUnprocessableRequest('use_for_tts and use_for_stt are the only updateable fields'); } @@ -248,9 +248,39 @@ router.put('/:sid', async(req, res) => { /* update the credential if provided */ try { - obj.credential = encryptCredential(req.body); - } catch (err) {} + const cred = await SpeechCredential.retrieve(sid); + if (1 === cred.length) { + const {credential, vendor} = cred[0]; + const o = JSON.parse(decrypt(credential)); + const { + use_custom_tts, + custom_tts_endpoint, + use_custom_stt, + custom_stt_endpoint + } = req.body; + const newCred = { + ...o, + region, + vendor, + aws_region, + use_custom_tts, + custom_tts_endpoint, + use_custom_stt, + custom_stt_endpoint + }; + logger.info({o, newCred}, 'updating speech credential with this new credential'); + obj.credential = encryptCredential(newCred); + obj.vendor = vendor; + } + else { + logger.info({sid}, 'speech credential not found!!'); + } + } catch (err) { + logger.error({err}, 'error updating speech credential'); + } + + logger.info({obj}, 'updating speech credential with changes'); const rowsAffected = await SpeechCredential.update(sid, obj); if (rowsAffected === 0) { return res.sendStatus(404); diff --git a/lib/utils/speech-utils.js b/lib/utils/speech-utils.js index 95fd560..56a08f1 100644 --- a/lib/utils/speech-utils.js +++ b/lib/utils/speech-utils.js @@ -67,6 +67,14 @@ const testMicrosoftTts = async(logger, credentials) => { custom_stt_endpoint } = credentials; + logger.info({ + api_key, + region, + use_custom_tts, + custom_tts_endpoint, + use_custom_stt, + custom_stt_endpoint + }, 'testing microsoft tts'); if (!api_key) throw new Error('testMicrosoftTts: credentials are missing api_key'); if (!region) throw new Error('testMicrosoftTts: credentials are missing region'); try {