initial changes to support nuance speech (#78)

* initial changes to support nuance speech

* fixes from testing
This commit is contained in:
Dave Horton
2022-10-31 09:59:36 -04:00
committed by GitHub
parent 8d303390b7
commit 46eee0cc60
5 changed files with 93 additions and 10 deletions
+56 -1
View File
@@ -12,7 +12,9 @@ const {
testAwsStt,
testMicrosoftStt,
testMicrosoftTts,
testWellSaidTts
testWellSaidTts,
testNuanceStt,
testNuanceTts
} = require('../../utils/speech-utils');
const obscureKey = (key) => {
@@ -35,6 +37,8 @@ const encryptCredential = (obj) => {
aws_region,
api_key,
region,
client_id,
secret,
use_custom_tts,
custom_tts_endpoint,
use_custom_stt,
@@ -78,6 +82,12 @@ const encryptCredential = (obj) => {
const wsData = JSON.stringify({api_key});
return encrypt(wsData);
case 'nuance':
assert(client_id, 'invalid nuance speech credential: client_id is required');
assert(secret, 'invalid nuance speech credential: secret is required');
const nuanceData = JSON.stringify({client_id, secret});
return encrypt(nuanceData);
default:
assert(false, `invalid or missing vendor: ${vendor}`);
}
@@ -160,6 +170,11 @@ router.get('/', async(req, res) => {
const o = JSON.parse(decrypt(credential));
obj.api_key = obscureKey(o.api_key);
}
else if ('nuance' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
obj.client_id = o.client_id;
obj.secret = obscureKey(o.secret);
}
return obj;
}));
} catch (err) {
@@ -205,6 +220,11 @@ router.get('/:sid', async(req, res) => {
const o = JSON.parse(decrypt(credential));
obj.api_key = obscureKey(o.api_key);
}
else if ('nuance' === obj.vendor) {
const o = JSON.parse(decrypt(credential));
obj.client_id = o.client_id;
obj.secret = obscureKey(o.secret);
}
res.status(200).json(obj);
} catch (err) {
sysError(logger, res, err);
@@ -419,6 +439,41 @@ router.get('/:sid/test', async(req, res) => {
}
}
}
else if (cred.vendor === 'nuance') {
const {getTtsVoices} = req.app.locals;
const {
client_id,
secret
} = credential;
if (cred.use_for_tts) {
try {
await testNuanceTts(logger, getTtsVoices, {
client_id,
secret
});
results.tts.status = 'ok';
SpeechCredential.ttsTestResult(sid, true);
} catch (err) {
logger.error({err}, 'error testing nuance tts');
const reason = err.statusCode === 401 ?
'invalid client_id or secret' :
(err.message || 'error accessing nuance tts service with provided credentials');
results.tts = {status: 'fail', reason};
SpeechCredential.ttsTestResult(sid, false);
}
}
if (cred.use_for_stt) {
try {
await testNuanceStt(logger, {client_id, secret});
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);
+12
View File
@@ -5,6 +5,16 @@ const AWS = require('aws-sdk');
const bent = require('bent');
const fs = require('fs');
const testNuanceTts = async(logger, getTtsVoices, credentials) => {
const voices = await getTtsVoices({vendor: 'nuance', credentials});
return voices;
};
const testNuanceStt = async(logger, credentials) => {
//TODO
return true;
};
const testGoogleTts = async(logger, credentials) => {
const client = new ttsGoogle.TextToSpeechClient({credentials});
await client.listVoices();
@@ -127,4 +137,6 @@ module.exports = {
testMicrosoftTts,
testMicrosoftStt,
testWellSaidStt,
testNuanceTts,
testNuanceStt
};