bugfix: say text continued to play after task was killed

This commit is contained in:
Dave Horton
2020-06-16 14:39:46 -04:00
parent 1dc4728574
commit 4e4ce0914e

View File

@@ -20,24 +20,27 @@ class TaskSay extends Task {
await super.exec(cs);
this.ep = ep;
try {
const filepath = [];
while (!this.killed && this.loop-- && this.ep.connected) {
let segment = 0;
do {
if (filepath.length <= segment) {
const opts = Object.assign({
text: this.text[segment],
// synthesize all of the text elements
const filepath = (await Promise.all(this.text.map(async(text) => {
const fp = await synthAudio({
text,
vendor: cs.speechSynthesisVendor,
language: cs.speechSynthesisLanguage,
voice: cs.speechSynthesisVoice,
salt: cs.callSid
}, this.synthesizer);
const path = await synthAudio(opts);
filepath.push(path);
cs.trackTmpFile(path);
}
}).catch((err) => this.logger.error(err, 'Error synthesizing text'));
if (fp) cs.trackTmpFile(fp);
return fp;
})))
.filter((fp) => fp && fp.length);
this.logger.debug({filepath}, 'synthesized files for tts');
while (!this.killed && this.loop-- && this.ep.connected) {
let segment = 0;
do {
await ep.play(filepath[segment]);
} while (++segment < this.text.length);
} while (!this.killed && ++segment < filepath.length);
}
} catch (err) {
this.logger.info(err, 'TaskSay:exec error');