mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
allow say.text to accept either a string or an array of strings
This commit is contained in:
@@ -6,7 +6,7 @@ class TaskSay extends Task {
|
||||
super(logger, opts);
|
||||
this.preconditions = TaskPreconditions.Endpoint;
|
||||
|
||||
this.text = this.data.text;
|
||||
this.text = Array.isArray(this.data.text) ? this.data.text : [this.data.text];
|
||||
this.loop = this.data.loop || 1;
|
||||
this.earlyMedia = this.data.earlyMedia === true || (parentTask && parentTask.earlyMedia);
|
||||
this.synthesizer = this.data.synthesizer || {};
|
||||
@@ -20,21 +20,23 @@ class TaskSay extends Task {
|
||||
await super.exec(cs);
|
||||
this.ep = ep;
|
||||
try {
|
||||
let filepath;
|
||||
const opts = Object.assign({
|
||||
text: this.text,
|
||||
vendor: cs.speechSynthesisVendor,
|
||||
language: cs.speechSynthesisLanguage,
|
||||
voice: cs.speechSynthesisVoice
|
||||
}, this.synthesizer);
|
||||
|
||||
const filepath = [];
|
||||
while (!this.killed && this.loop--) {
|
||||
if (!filepath) {
|
||||
this.logger.debug('TaskSay:exec - retrieving synthesized audio');
|
||||
filepath = await synthAudio(opts);
|
||||
cs.trackTmpFile(filepath);
|
||||
}
|
||||
await ep.play(filepath);
|
||||
let segment = 0;
|
||||
do {
|
||||
if (filepath.length <= segment) {
|
||||
const opts = Object.assign({
|
||||
text: this.text[segment],
|
||||
vendor: cs.speechSynthesisVendor,
|
||||
language: cs.speechSynthesisLanguage,
|
||||
voice: cs.speechSynthesisVoice
|
||||
}, this.synthesizer);
|
||||
const path = await synthAudio(opts);
|
||||
filepath.push(path);
|
||||
cs.trackTmpFile(path);
|
||||
}
|
||||
await ep.play(filepath[segment]);
|
||||
} while (++segment < this.text.length);
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.info(err, 'TaskSay:exec error');
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
},
|
||||
"say": {
|
||||
"properties": {
|
||||
"text": "string",
|
||||
"text": "string|array",
|
||||
"loop": "number",
|
||||
"synthesizer": "#synthesizer",
|
||||
"earlyMedia": "boolean"
|
||||
|
||||
@@ -117,21 +117,21 @@ class Task extends Emitter {
|
||||
const dSpec = specData.properties[dKey];
|
||||
debug(`Task:validate validating property ${dKey} with value ${JSON.stringify(dVal)}`);
|
||||
|
||||
if (typeof dSpec === 'string' && ['number', 'string', 'object', 'boolean'].includes(dSpec)) {
|
||||
// simple types
|
||||
if (typeof dVal !== specData.properties[dKey]) {
|
||||
throw new Error(`${name}: property ${dKey} has invalid data type`);
|
||||
}
|
||||
}
|
||||
else if (typeof dSpec === 'string' && dSpec === 'array') {
|
||||
if (typeof dSpec === 'string' && dSpec === 'array') {
|
||||
if (!Array.isArray(dVal)) throw new Error(`${name}: property ${dKey} is not an array`);
|
||||
}
|
||||
else if (typeof dSpec === 'string' && dSpec.includes('|')) {
|
||||
const types = dSpec.split('|').map((t) => t.trim());
|
||||
if (!types.includes(typeof dVal)) {
|
||||
if (!types.includes(typeof dVal) && !(types.includes('array') && Array.isArray(dVal))) {
|
||||
throw new Error(`${name}: property ${dKey} has invalid data type, must be one of ${types}`);
|
||||
}
|
||||
}
|
||||
else if (typeof dSpec === 'string' && ['number', 'string', 'object', 'boolean'].includes(dSpec)) {
|
||||
// simple types
|
||||
if (typeof dVal !== specData.properties[dKey]) {
|
||||
throw new Error(`${name}: property ${dKey} has invalid data type`);
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(dSpec) && dSpec[0].startsWith('#')) {
|
||||
const name = dSpec[0].slice(1);
|
||||
for (const item of dVal) {
|
||||
|
||||
Reference in New Issue
Block a user