mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-24 13:02:16 +00:00
add support for ibm speech credentials, and test for ibm tts (#82)
* add support for ibm speech credentials, and test for ibm tts * add stt testing for ibm watson
This commit is contained in:
@@ -15,7 +15,9 @@ const {
|
||||
testWellSaidTts,
|
||||
testNuanceStt,
|
||||
testNuanceTts,
|
||||
testDeepgramStt
|
||||
testDeepgramStt,
|
||||
testIbmTts,
|
||||
testIbmStt
|
||||
} = require('../../utils/speech-utils');
|
||||
|
||||
const obscureKey = (key) => {
|
||||
@@ -43,7 +45,11 @@ const encryptCredential = (obj) => {
|
||||
use_custom_tts,
|
||||
custom_tts_endpoint,
|
||||
use_custom_stt,
|
||||
custom_stt_endpoint
|
||||
custom_stt_endpoint,
|
||||
tts_api_key,
|
||||
tts_region,
|
||||
stt_api_key,
|
||||
stt_region
|
||||
} = obj;
|
||||
|
||||
switch (vendor) {
|
||||
@@ -94,6 +100,10 @@ const encryptCredential = (obj) => {
|
||||
const deepgramData = JSON.stringify({api_key});
|
||||
return encrypt(deepgramData);
|
||||
|
||||
case 'ibm':
|
||||
const ibmData = JSON.stringify({tts_api_key, tts_region, stt_api_key, stt_region});
|
||||
return encrypt(ibmData);
|
||||
|
||||
default:
|
||||
assert(false, `invalid or missing vendor: ${vendor}`);
|
||||
}
|
||||
@@ -268,7 +278,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, region, aws_region} = req.body;
|
||||
const {use_for_tts, use_for_stt, region, aws_region, stt_region, tts_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');
|
||||
}
|
||||
@@ -301,7 +311,9 @@ router.put('/:sid', async(req, res) => {
|
||||
use_custom_tts,
|
||||
custom_tts_endpoint,
|
||||
use_custom_stt,
|
||||
custom_stt_endpoint
|
||||
custom_stt_endpoint,
|
||||
stt_region,
|
||||
tts_region
|
||||
};
|
||||
logger.info({o, newCred}, 'updating speech credential with this new credential');
|
||||
obj.credential = encryptCredential(newCred);
|
||||
@@ -501,6 +513,40 @@ router.get('/:sid/test', async(req, res) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cred.vendor === 'ibm') {
|
||||
const {getTtsVoices} = req.app.locals;
|
||||
|
||||
if (cred.use_for_tts) {
|
||||
const {tts_api_key, tts_region} = credential;
|
||||
try {
|
||||
await testIbmTts(logger, getTtsVoices, {
|
||||
tts_api_key,
|
||||
tts_region
|
||||
});
|
||||
results.tts.status = 'ok';
|
||||
SpeechCredential.ttsTestResult(sid, true);
|
||||
} catch (err) {
|
||||
logger.error({err}, 'error testing ibm tts');
|
||||
const reason = err.statusCode === 401 ?
|
||||
'invalid api_key or region' :
|
||||
(err.message || 'error accessing ibm tts service with provided credentials');
|
||||
results.tts = {status: 'fail', reason};
|
||||
SpeechCredential.ttsTestResult(sid, false);
|
||||
}
|
||||
}
|
||||
if (cred.use_for_stt) {
|
||||
const {stt_api_key, stt_region} = credential;
|
||||
try {
|
||||
await testIbmStt(logger, {stt_region, stt_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);
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
|
||||
Reference in New Issue
Block a user