mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-23 12:32:06 +00:00
initial changes to support nuance speech (#78)
* initial changes to support nuance speech * fixes from testing
This commit is contained in:
@@ -40,7 +40,8 @@ const {
|
||||
retrieveSet,
|
||||
addKey,
|
||||
retrieveKey,
|
||||
deleteKey
|
||||
deleteKey,
|
||||
getTtsVoices
|
||||
} = require('@jambonz/realtimedb-helpers')({
|
||||
host: process.env.JAMBONES_REDIS_HOST || 'localhost',
|
||||
port: process.env.JAMBONES_REDIS_PORT || 6379
|
||||
@@ -78,6 +79,7 @@ app.locals = {
|
||||
addKey,
|
||||
retrieveKey,
|
||||
deleteKey,
|
||||
getTtsVoices,
|
||||
lookupAppBySid,
|
||||
lookupAccountBySid,
|
||||
lookupAccountByPhoneNumber,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Generated
+21
-7
@@ -12,7 +12,7 @@
|
||||
"@google-cloud/speech": "^4.10.2",
|
||||
"@google-cloud/text-to-speech": "^3.4.0",
|
||||
"@jambonz/db-helpers": "^0.6.19",
|
||||
"@jambonz/realtimedb-helpers": "^0.4.35",
|
||||
"@jambonz/realtimedb-helpers": "^0.5.1",
|
||||
"@jambonz/time-series": "^0.2.5",
|
||||
"argon2-ffi": "^2.0.0",
|
||||
"aws-sdk": "^2.1152.0",
|
||||
@@ -832,16 +832,18 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/realtimedb-helpers": {
|
||||
"version": "0.4.35",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.4.35.tgz",
|
||||
"integrity": "sha512-lfNTlWRnLbOKVRDto1nUgOmr2jlmOHxslg+Zs9dSB8eEEkIqCNZn9f5kxxXThVpRSrCtsgGsX/w1wXygGiTn5w==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.5.1.tgz",
|
||||
"integrity": "sha512-8elXD2W6tYTPBcDLlBx/n4q6SQXeRIFkv9wib+zDAU9qEdUJgTSA/nXpZqUBO1ucXEoGOrD3KworrkEBmwX58g==",
|
||||
"dependencies": {
|
||||
"@google-cloud/text-to-speech": "^4.0.3",
|
||||
"@grpc/grpc-js": "^1.7.3",
|
||||
"@jambonz/promisify-redis": "^0.0.6",
|
||||
"aws-sdk": "^2.1238.0",
|
||||
"bent": "^7.3.12",
|
||||
"debug": "^4.3.3",
|
||||
"form-urlencoded": "^6.1.0",
|
||||
"google-protobuf": "^3.21.2",
|
||||
"microsoft-cognitiveservices-speech-sdk": "^1.24.0",
|
||||
"redis": "^3.1.2",
|
||||
"undici": "^5.11.0"
|
||||
@@ -3399,6 +3401,11 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/google-protobuf": {
|
||||
"version": "3.21.2",
|
||||
"resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.21.2.tgz",
|
||||
"integrity": "sha512-3MSOYFO5U9mPGikIYCzK0SaThypfGgS6bHqrUGXG3DPHCrb+txNqeEcns1W0lkGfk0rCyNXm7xB9rMxnCiZOoA=="
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.6",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
|
||||
@@ -7648,16 +7655,18 @@
|
||||
}
|
||||
},
|
||||
"@jambonz/realtimedb-helpers": {
|
||||
"version": "0.4.35",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.4.35.tgz",
|
||||
"integrity": "sha512-lfNTlWRnLbOKVRDto1nUgOmr2jlmOHxslg+Zs9dSB8eEEkIqCNZn9f5kxxXThVpRSrCtsgGsX/w1wXygGiTn5w==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.5.1.tgz",
|
||||
"integrity": "sha512-8elXD2W6tYTPBcDLlBx/n4q6SQXeRIFkv9wib+zDAU9qEdUJgTSA/nXpZqUBO1ucXEoGOrD3KworrkEBmwX58g==",
|
||||
"requires": {
|
||||
"@google-cloud/text-to-speech": "^4.0.3",
|
||||
"@grpc/grpc-js": "^1.7.3",
|
||||
"@jambonz/promisify-redis": "^0.0.6",
|
||||
"aws-sdk": "^2.1238.0",
|
||||
"bent": "^7.3.12",
|
||||
"debug": "^4.3.3",
|
||||
"form-urlencoded": "^6.1.0",
|
||||
"google-protobuf": "^3.21.2",
|
||||
"microsoft-cognitiveservices-speech-sdk": "^1.24.0",
|
||||
"redis": "^3.1.2",
|
||||
"undici": "^5.11.0"
|
||||
@@ -9618,6 +9627,11 @@
|
||||
"node-forge": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"google-protobuf": {
|
||||
"version": "3.21.2",
|
||||
"resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.21.2.tgz",
|
||||
"integrity": "sha512-3MSOYFO5U9mPGikIYCzK0SaThypfGgS6bHqrUGXG3DPHCrb+txNqeEcns1W0lkGfk0rCyNXm7xB9rMxnCiZOoA=="
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.6",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
"@google-cloud/speech": "^4.10.2",
|
||||
"@google-cloud/text-to-speech": "^3.4.0",
|
||||
"@jambonz/db-helpers": "^0.6.19",
|
||||
"@jambonz/realtimedb-helpers": "^0.4.35",
|
||||
"@jambonz/realtimedb-helpers": "^0.5.1",
|
||||
"@jambonz/time-series": "^0.2.5",
|
||||
"argon2-ffi": "^2.0.0",
|
||||
"aws-sdk": "^2.1152.0",
|
||||
|
||||
Reference in New Issue
Block a user