mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
modify tts and say task to track current playback id and match against start and stop events
This commit is contained in:
@@ -264,7 +264,6 @@ class TaskSay extends TtsTask {
|
|||||||
await this.playToConfMember(ep, memberId, confName, confUuid, filepath[segment]);
|
await this.playToConfMember(ep, memberId, confName, confUuid, filepath[segment]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let playbackId;
|
|
||||||
const isStreaming = filepath[segment].startsWith('say:{');
|
const isStreaming = filepath[segment].startsWith('say:{');
|
||||||
if (isStreaming) {
|
if (isStreaming) {
|
||||||
const arr = /^say:\{.*\}\s*(.*)$/.exec(filepath[segment]);
|
const arr = /^say:\{.*\}\s*(.*)$/.exec(filepath[segment]);
|
||||||
@@ -283,10 +282,10 @@ class TaskSay extends TtsTask {
|
|||||||
* If we got a playback id on both the start and stop events, and they don't match,
|
* If we got a playback id on both the start and stop events, and they don't match,
|
||||||
* then we must have received a playback-stop event for an earlier play request.
|
* then we must have received a playback-stop event for an earlier play request.
|
||||||
*/
|
*/
|
||||||
const unmatchedResponse = (!!playbackId && !!evt.variable_tts_playback_id) &&
|
// eslint-disable-next-line max-len
|
||||||
evt.variable_tts_playback_id !== playbackId;
|
const unmatchedResponse = (!!this.playbackId && !!evt.variable_tts_playback_id) && evt.variable_tts_playback_id !== this.playbackId;
|
||||||
if (unmatchedResponse) {
|
if (unmatchedResponse) {
|
||||||
this.logger.info({currentPlaybackId: playbackId, stopPPlaybackId: evt.variable_tts_playback_id},
|
this.logger.info({currentPlaybackId: this.playbackId, stopPlaybackId: evt.variable_tts_playback_id},
|
||||||
'Say:exec discarding playback-stop for earlier play');
|
'Say:exec discarding playback-stop for earlier play');
|
||||||
ep.once('playback-stop', this._boundOnPlaybackStop);
|
ep.once('playback-stop', this._boundOnPlaybackStop);
|
||||||
|
|
||||||
@@ -358,9 +357,16 @@ class TaskSay extends TtsTask {
|
|||||||
};
|
};
|
||||||
this._boundOnPlaybackStop = onPlaybackStop.bind(this);
|
this._boundOnPlaybackStop = onPlaybackStop.bind(this);
|
||||||
|
|
||||||
ep.once('playback-start', (evt) => {
|
const onPlaybackStart = (evt) => {
|
||||||
try {
|
try {
|
||||||
playbackId = evt.variable_tts_playback_id;
|
// eslint-disable-next-line max-len
|
||||||
|
const unmatchedResponse = (!!this.playbackId && !!evt.variable_tts_playback_id) && evt.variable_tts_playback_id !== this.playbackId;
|
||||||
|
if (unmatchedResponse) {
|
||||||
|
this.logger.info({currentPlaybackId: this.playbackId, stopPlaybackId: evt.variable_tts_playback_id},
|
||||||
|
'Say:exec playback-start - unmatched playback_id');
|
||||||
|
ep.once('playback-start', this._boundOnPlaybackStart);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.logger.debug({evt},
|
this.logger.debug({evt},
|
||||||
`Say got playback-start ${evt.variable_tts_playback_id ? evt.variable_tts_playback_id : ''}`);
|
`Say got playback-start ${evt.variable_tts_playback_id ? evt.variable_tts_playback_id : ''}`);
|
||||||
if (this.otelSpan) {
|
if (this.otelSpan) {
|
||||||
@@ -374,8 +380,11 @@ class TaskSay extends TtsTask {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info({err}, 'Error handling playback-start event');
|
this.logger.info({err}, 'Error handling playback-start event');
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
this._boundOnPlaybackStart = onPlaybackStart.bind(this);
|
||||||
|
|
||||||
ep.once('playback-stop', this._boundOnPlaybackStop);
|
ep.once('playback-stop', this._boundOnPlaybackStop);
|
||||||
|
ep.once('playback-start', this._boundOnPlaybackStart);
|
||||||
|
|
||||||
// wait for playback-stop event received to confirm if the playback is successful
|
// wait for playback-stop event received to confirm if the playback is successful
|
||||||
this._playPromise = new Promise((resolve, reject) => {
|
this._playPromise = new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -3,6 +3,16 @@ const { TaskPreconditions } = require('../utils/constants');
|
|||||||
const { SpeechCredentialError } = require('../utils/error');
|
const { SpeechCredentialError } = require('../utils/error');
|
||||||
const dbUtils = require('../utils/db-utils');
|
const dbUtils = require('../utils/db-utils');
|
||||||
|
|
||||||
|
const extractPlaybackId = (str) => {
|
||||||
|
// Match say:{...} and capture the content inside braces
|
||||||
|
const match = str.match(/say:\{([^}]*)\}/);
|
||||||
|
if (!match) return null;
|
||||||
|
|
||||||
|
// Look for playback_id=value within the captured content
|
||||||
|
const playbackMatch = match[1].match(/playback_id=([^,]*)/);
|
||||||
|
return playbackMatch ? playbackMatch[1] : null;
|
||||||
|
};
|
||||||
|
|
||||||
class TtsTask extends Task {
|
class TtsTask extends Task {
|
||||||
|
|
||||||
constructor(logger, data, parentTask) {
|
constructor(logger, data, parentTask) {
|
||||||
@@ -309,7 +319,8 @@ class TtsTask extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.debug('Say: a streaming tts api will be used');
|
this.playbackId = extractPlaybackId(filePath);
|
||||||
|
this.logger.debug(`Say: a streaming tts api will be used, playback_id=${this.playbackId}`);
|
||||||
const modifiedPath = filePath.replace('say:{', `say:{session-uuid=${ep.uuid},`);
|
const modifiedPath = filePath.replace('say:{', `say:{session-uuid=${ep.uuid},`);
|
||||||
return modifiedPath;
|
return modifiedPath;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user