mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add lex support
This commit is contained in:
@@ -41,6 +41,11 @@ class Dialogflow extends Task {
|
||||
}
|
||||
if (this.data.actionHook) this.actionHook = this.data.actionHook;
|
||||
if (this.data.thinkingMusic) this.thinkingMusic = this.data.thinkingMusic;
|
||||
if (this.data.tts) {
|
||||
this.vendor = this.data.tts.vendor || 'default';
|
||||
this.language = this.data.tts.language || 'default';
|
||||
this.voice = this.data.tts.voice || 'default';
|
||||
}
|
||||
}
|
||||
|
||||
get name() { return TaskName.Dialogflow; }
|
||||
@@ -94,6 +99,11 @@ class Dialogflow extends Task {
|
||||
async init(cs, ep) {
|
||||
this.ep = ep;
|
||||
try {
|
||||
if (this.vendor === 'default') {
|
||||
this.vendor = cs.speechSynthesisVendor;
|
||||
this.language = cs.speechSynthesisLanguage;
|
||||
this.voice = cs.speechSynthesisVoice;
|
||||
}
|
||||
this.ep.addCustomEventListener('dialogflow::intent', this._onIntent.bind(this, ep, cs));
|
||||
this.ep.addCustomEventListener('dialogflow::transcription', this._onTranscription.bind(this, ep, cs));
|
||||
this.ep.addCustomEventListener('dialogflow::audio_provided', this._onAudioProvided.bind(this, ep, cs));
|
||||
@@ -117,7 +127,7 @@ class Dialogflow extends Task {
|
||||
* @param {*} ep - media server endpoint
|
||||
* @param {*} evt - event data
|
||||
*/
|
||||
_onIntent(ep, cs, evt) {
|
||||
async _onIntent(ep, cs, evt) {
|
||||
const intent = new Intent(this.logger, evt);
|
||||
|
||||
if (intent.isEmpty) {
|
||||
@@ -178,6 +188,61 @@ class Dialogflow extends Task {
|
||||
this.digitBuffer = new DigitBuffer(this.logger, opts);
|
||||
this.digitBuffer.once('fulfilled', this._onDtmfEntryComplete.bind(this, ep));
|
||||
}
|
||||
|
||||
/* if we are using tts and a message was provided, play it out */
|
||||
if (this.vendor && intent.fulfillmentText && intent.fulfillmentText.length > 0) {
|
||||
const {srf} = cs;
|
||||
const {synthAudio} = srf.locals.dbHelpers;
|
||||
this.waitingForPlayStart = false;
|
||||
|
||||
// start a new intent, (we want to continue to listen during the audio playback)
|
||||
// _unless_ we are transferring or ending the session
|
||||
if (!this.hangupAfterPlayDone) {
|
||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
||||
}
|
||||
|
||||
try {
|
||||
const obj = {
|
||||
text: intent.fulfillmentText,
|
||||
vendor: this.vendor,
|
||||
language: this.language,
|
||||
voice: this.voice,
|
||||
salt: cs.callSid
|
||||
};
|
||||
this.logger.debug({obj}, 'Dialogflow:_onIntent - playing message via tts');
|
||||
const fp = await synthAudio(obj);
|
||||
if (fp) cs.trackTmpFile(fp);
|
||||
this.playInProgress = true;
|
||||
this.curentAudioFile = fp;
|
||||
|
||||
this.logger.debug(`starting to play tts ${fp}`);
|
||||
if (this.events.includes('start-play')) {
|
||||
this._performHook(cs, this.eventHook, {event: 'start-play', data: {path: fp}});
|
||||
}
|
||||
await ep.play(fp);
|
||||
if (this.events.includes('stop-play')) {
|
||||
this._performHook(cs, this.eventHook, {event: 'stop-play', data: {path: fp}});
|
||||
}
|
||||
this.logger.debug(`finished ${fp}`);
|
||||
|
||||
if (this.curentAudioFile === fp) {
|
||||
this.playInProgress = false;
|
||||
}
|
||||
this.greetingPlayed = true;
|
||||
|
||||
if (this.hangupAfterPlayDone) {
|
||||
this.logger.info('hanging up since intent was marked end interaction and we completed final prompt');
|
||||
this.performAction({dialogflowResult: 'completed'});
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
else {
|
||||
// every time we finish playing a prompt, start the no-input timer
|
||||
this._startNoinputTimer(ep, cs);
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'Dialogflow:_onIntent - error playing tts');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,6 +296,9 @@ class Dialogflow extends Task {
|
||||
* @param {*} evt - event data
|
||||
*/
|
||||
async _onAudioProvided(ep, cs, evt) {
|
||||
|
||||
if (this.vendor) return;
|
||||
|
||||
this.waitingForPlayStart = false;
|
||||
|
||||
// kill filler audio
|
||||
|
||||
Reference in New Issue
Block a user