mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-19 04:17:44 +00:00
say verb support play audio in array (#482)
* say verb support play audio in array * fixed review comments * added separated testcase
This commit is contained in:
@@ -50,6 +50,15 @@ class TaskSay extends Task {
|
|||||||
return `${this.name}{${this.text[0]}}`;
|
return `${this.name}{${this.text[0]}}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_validateURL(urlString) {
|
||||||
|
try {
|
||||||
|
new URL(urlString);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label}) {
|
async _synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label}) {
|
||||||
const {srf} = cs;
|
const {srf} = cs;
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf);
|
||||||
@@ -153,7 +162,7 @@ class TaskSay extends Task {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const arr = this.text.map((t) => generateAudio(t));
|
const arr = this.text.map((t) => (this._validateURL(t) ? t : generateAudio(t)));
|
||||||
return (await Promise.all(arr)).filter((fp) => fp && fp.length);
|
return (await Promise.all(arr)).filter((fp) => fp && fp.length);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info(err, 'TaskSay:exec error');
|
this.logger.info(err, 'TaskSay:exec error');
|
||||||
|
|||||||
@@ -84,6 +84,46 @@ test('\'config\' reset synthesizer tests', async(t) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Say verb array test', async(t) => {
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
|
||||||
|
// GIVEN
|
||||||
|
const verbs = [
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"synthesizer": {
|
||||||
|
"vendor": "microsft",
|
||||||
|
"voice": "foobar"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"reset": 'synthesizer',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
verb: 'say',
|
||||||
|
text: ['hello', 'https://samplelib.com/lib/preview/mp3/sample-3s.mp3']
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const from = 'say_test_success';
|
||||||
|
await provisionCallHook(from, verbs)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-success-received-bye.xml', '172.38.0.10', from);
|
||||||
|
t.pass('say: succeeds when using using account credentials');
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const {MICROSOFT_CUSTOM_API_KEY, MICROSOFT_DEPLOYMENT_ID, MICROSOFT_CUSTOM_REGION, MICROSOFT_CUSTOM_VOICE} = process.env;
|
const {MICROSOFT_CUSTOM_API_KEY, MICROSOFT_DEPLOYMENT_ID, MICROSOFT_CUSTOM_REGION, MICROSOFT_CUSTOM_VOICE} = process.env;
|
||||||
if (MICROSOFT_CUSTOM_API_KEY && MICROSOFT_DEPLOYMENT_ID && MICROSOFT_CUSTOM_REGION && MICROSOFT_CUSTOM_VOICE) {
|
if (MICROSOFT_CUSTOM_API_KEY && MICROSOFT_DEPLOYMENT_ID && MICROSOFT_CUSTOM_REGION && MICROSOFT_CUSTOM_VOICE) {
|
||||||
test('\'say\' tests - microsoft custom voice', async(t) => {
|
test('\'say\' tests - microsoft custom voice', async(t) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user