Compare commits

...

3 Commits

Author SHA1 Message Date
Quan HL
4e59bcb9fa fix: update custom stt/tss url 2023-03-05 06:33:25 +07:00
Dave Horton
07421d830e change property names for custom speech 2023-03-02 15:28:25 -05:00
Dave Horton
5c687aebdd add support for custom speech api 2023-03-02 14:04:03 -05:00
2 changed files with 37 additions and 5 deletions

View File

@@ -86,6 +86,14 @@ SpeechCredential.fields = [
{
name: 'last_tested',
type: 'date'
},
{
name: 'custom_tts_url',
type: 'date'
},
{
name: 'custom_stt_url',
type: 'date'
}
];

View File

@@ -53,7 +53,10 @@ const encryptCredential = (obj) => {
stt_api_key,
stt_region,
riva_server_uri,
instance_id
instance_id,
custom_stt_url,
custom_tts_url,
auth_token = ''
} = obj;
switch (vendor) {
@@ -119,7 +122,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, custom_stt_url, custom_tts_url});
return encrypt(customData);
}
else assert(false, `invalid or missing vendor: ${vendor}`);
}
};
@@ -230,6 +237,12 @@ 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));
obj.auth_token = obscureKey(o.auth_token);
obj.custom_stt_url = o.custom_stt_url;
obj.custom_tts_url = o.custom_tts_url;
}
return obj;
}));
} catch (err) {
@@ -295,6 +308,12 @@ 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);
obj.custom_stt_url = o.custom_stt_url;
obj.custom_tts_url = o.custom_tts_url;
}
res.status(200).json(obj);
} catch (err) {
sysError(logger, res, err);
@@ -324,7 +343,8 @@ 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, stt_region, tts_region, riva_server_uri} = req.body;
const {use_for_tts, use_for_stt, region, aws_region, stt_region, tts_region,
riva_server_uri, custom_stt_url, custom_tts_url} = 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');
}
@@ -360,7 +380,9 @@ router.put('/:sid', async(req, res) => {
custom_stt_endpoint,
stt_region,
tts_region,
riva_server_uri
riva_server_uri,
custom_stt_url,
custom_tts_url
};
logger.info({o, newCred}, 'updating speech credential with this new credential');
obj.credential = encryptCredential(newCred);
@@ -592,7 +614,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 +630,7 @@ router.get('/:sid/test', async(req, res) => {
}
res.status(200).json(results);
} catch (err) {
sysError(logger, res, err);
}