mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
bugfix: say text continued to play after task was killed
This commit is contained in:
@@ -20,24 +20,27 @@ class TaskSay extends Task {
|
|||||||
await super.exec(cs);
|
await super.exec(cs);
|
||||||
this.ep = ep;
|
this.ep = ep;
|
||||||
try {
|
try {
|
||||||
const filepath = [];
|
// 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
|
||||||
|
}).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) {
|
while (!this.killed && this.loop-- && this.ep.connected) {
|
||||||
let segment = 0;
|
let segment = 0;
|
||||||
do {
|
do {
|
||||||
if (filepath.length <= segment) {
|
|
||||||
const opts = Object.assign({
|
|
||||||
text: this.text[segment],
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
await ep.play(filepath[segment]);
|
await ep.play(filepath[segment]);
|
||||||
} while (++segment < this.text.length);
|
} while (!this.killed && ++segment < filepath.length);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info(err, 'TaskSay:exec error');
|
this.logger.info(err, 'TaskSay:exec error');
|
||||||
|
|||||||
Reference in New Issue
Block a user