mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
Fix/playback race by fs generates playback (#1331)
* update to speech-utils that generates playback id * modify tts and say task to track current playback id and match against start and stop events * bump speech utils * wip * wip * fix race condition where say with playbackId gets stop event from previous play from cache file * logging * wip * fix comparison when playing cached files * logging
This commit is contained in:
@@ -3,6 +3,16 @@ const { TaskPreconditions } = require('../utils/constants');
|
||||
const { SpeechCredentialError } = require('../utils/error');
|
||||
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 {
|
||||
|
||||
constructor(logger, data, parentTask) {
|
||||
@@ -22,6 +32,11 @@ class TtsTask extends Task {
|
||||
this.disableTtsCache = this.data.disableTtsCache;
|
||||
this.options = this.synthesizer.options || {};
|
||||
this.instructions = this.data.instructions;
|
||||
this.playbackIds = [];
|
||||
}
|
||||
|
||||
getPlaybackId(offset) {
|
||||
return this.playbackIds[offset];
|
||||
}
|
||||
|
||||
async exec(cs) {
|
||||
@@ -280,6 +295,7 @@ class TtsTask extends Task {
|
||||
renderForCaching: preCache
|
||||
});
|
||||
if (!filePath.startsWith('say:')) {
|
||||
this.playbackIds.push(null);
|
||||
this.logger.debug(`Say: file ${filePath}, served from cache ${servedFromCache}`);
|
||||
if (filePath) cs.trackTmpFile(filePath);
|
||||
if (this.otelSpan) {
|
||||
@@ -309,7 +325,8 @@ class TtsTask extends Task {
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.logger.debug('Say: a streaming tts api will be used');
|
||||
this.playbackIds.push(extractPlaybackId(filePath));
|
||||
this.logger.debug({playbackIds: this.playbackIds}, 'Say: a streaming tts api will be used');
|
||||
const modifiedPath = filePath.replace('say:{', `say:{session-uuid=${ep.uuid},`);
|
||||
return modifiedPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user