mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
major refactoring
This commit is contained in:
@@ -2,44 +2,44 @@ const Task = require('./task');
|
||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||
|
||||
class TaskSay extends Task {
|
||||
constructor(logger, opts) {
|
||||
constructor(logger, opts, parentTask) {
|
||||
super(logger, opts);
|
||||
this.preconditions = TaskPreconditions.Endpoint;
|
||||
|
||||
this.text = this.data.text;
|
||||
this.voice = this.data.synthesizer.voice;
|
||||
this.earlyMedia = this.data.earlyMedia === true;
|
||||
|
||||
switch (this.data.synthesizer.vendor) {
|
||||
case 'google':
|
||||
this.ttsEngine = 'google_tts';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`unsupported tts vendor ${this.data.synthesizer.vendor}`);
|
||||
this.earlyMedia = this.data.earlyMedia === true || (parentTask && parentTask.earlyMedia);
|
||||
if (this.data.synthesizer) {
|
||||
this.voice = this.data.synthesizer.voice;
|
||||
switch (this.data.synthesizer.vendor) {
|
||||
case 'google':
|
||||
this.ttsEngine = 'google_tts';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`unsupported tts vendor ${this.data.synthesizer.vendor}`);
|
||||
}
|
||||
}
|
||||
this.sayComplete = false;
|
||||
}
|
||||
|
||||
get name() { return TaskName.Say; }
|
||||
|
||||
async exec(cs, ep) {
|
||||
super.exec(cs);
|
||||
this.ep = ep;
|
||||
try {
|
||||
await ep.speak({
|
||||
ttsEngine: 'google_tts',
|
||||
voice: this.voice,
|
||||
voice: this.voice || this.callSession.speechSynthesisVoice,
|
||||
text: this.text
|
||||
});
|
||||
} catch (err) {
|
||||
this.logger.info(err, 'TaskSay:exec error');
|
||||
}
|
||||
this.emit('playDone');
|
||||
this.sayComplete = true;
|
||||
}
|
||||
|
||||
kill() {
|
||||
super.kill();
|
||||
if (this.ep.connected && !this.sayComplete) {
|
||||
if (this.ep.connected) {
|
||||
this.logger.debug('TaskSay:kill - killing audio');
|
||||
this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user