Skip to content

fix errors on filler noises #795 795 #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions lib/session/call-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class CallSession extends Emitter {
language: this.application?.speech_synthesis_language,
voice: this.application?.speech_synthesis_voice,
};
this.awaitCommands = false;

assert(rootSpan);

Expand Down Expand Up @@ -1816,6 +1817,7 @@ Duration=${duration} `

async _onCommand({msgid, command, call_sid, queueCommand, data}) {
this.logger.info({msgid, command, queueCommand, data}, 'CallSession:_onCommand - received command');
this.awaitCommands = false
let resolution;
switch (command) {
case 'redirect':
Expand Down Expand Up @@ -2504,10 +2506,26 @@ Duration=${duration} `
}
}

_startFillerNoiseTimer() {
this._clearFillerNoiseTimer();
this._fillerNoiseTimer = setTimeout(() => {
if (this.awaitCommands) {
Copy link
Contributor

@Catharsis68 Catharsis68 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an additional check for the case the freeswitch endpoint is not available anymore

Suggested change
if (this.awaitCommands) {
if (this.awaitCommands && this.ep?.connected) {

this.logger.debug('CallSession:_awaitCommandsOrHangup - playing filler noise');
this.ep.play(this.fillerNoise.url);
}
}, this.fillerNoise.startDelaySecs * 1000);
}

_clearFillerNoiseTimer() {
if (this._fillerNoiseTimer) clearTimeout(this._fillerNoiseTimer);
this._fillerNoiseTimer = null;
}

_awaitCommandsOrHangup() {
assert(!this.wakeupResolver);
return new Promise((resolve, reject) => {
this.logger.info('_awaitCommandsOrHangup - waiting...');
this.awaitCommands = true;
this.wakeupResolver = resolve;

if (this._actionHookDelayProcessor) {
Expand All @@ -2524,14 +2542,18 @@ Duration=${duration} `
if (this.fillerNoise?.url && this.ep?.connected && !this.ep2) {
this.logger.debug('CallSession:_awaitCommandsOrHangup - playing filler noise');
this._isPlayingFillerNoise = true;
this.ep.play(this.fillerNoise.url);
this.ep.once('playback-start', (evt) => {
if (evt.file === this.fillerNoise.url && !this._isPlayingFillerNoise) {
this.logger.info('CallSession:_awaitCommandsOrHangup - filler noise started');
this.ep.api('uuid_break', this.ep.uuid)
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
}
});
if (this.fillerNoise.startDelaySecs > 0) {
this._startFillerNoiseTimer();
} else {
this.ep.play(this.fillerNoise.url);
this.ep.once('playback-start', (evt) => {
if (evt.file === this.fillerNoise.url && !this._isPlayingFillerNoise) {
this.logger.info('CallSession:_awaitCommandsOrHangup - filler noise started');
this.ep.api('uuid_break', this.ep.uuid)
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
}
});
}
}
});
}
Expand Down
13 changes: 11 additions & 2 deletions lib/tasks/gather.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class TaskGather extends SttTask {
...(cs.fillerNoise || {}),
...(this.fillerNoise || {})
};
this._fillerNoiseKill = false;

this.vad = {
...(cs.vad || {}),
Expand Down Expand Up @@ -638,19 +639,26 @@ class TaskGather extends SttTask {
this._fillerNoiseOn = true;
this.ep.once('playback-start', (evt) => {
if (evt.file === this.fillerNoise.url && !this._fillerNoiseOn) {
this.logger.info('Filler noise already started');
return;
/*
this.logger.info({evt}, 'Gather:_startFillerNoise - race condition - kill filler noise here');
this.ep.api('uuid_break', this.ep.uuid)
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
return;
*/
} else this.logger.debug({evt}, 'Gather:_startFillerNoise - playback started');
});
}

_startFillerNoiseTimer() {
this._clearFillerNoiseTimer();
this._fillerNoiseTimer = setTimeout(() => {
this.logger.debug('Gather:_startFillerNoiseTimer - playing filler noise');
this._startFillerNoise();
if (!this._fillerNoiseKill) {
this.logger.debug('Gather:_startFillerNoiseTimer - playing filler noise');
this._startFillerNoise();
}
return;
}, this.fillerNoise.startDelaySecs * 1000);
}

Expand All @@ -672,6 +680,7 @@ class TaskGather extends SttTask {
this.logger.debug('Gather:_killAudio: killing playback of any audio');
this.playComplete = true;
this._fillerNoiseOn = false; // in a race, if we just started audio it may sneak through here
this._fillerNoiseKill = true;
this.ep.api('uuid_break', this.ep.uuid)
.catch((err) => this.logger.info(err, 'Error killing audio'));
}
Expand Down