mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
Feature/precache audio (#609)
* wip * fix for establishing vendor etc * more fixes * avoid a pre-caching attempt if synth settings change
This commit is contained in:
@@ -19,6 +19,7 @@ const HttpRequestor = require('../utils/http-requestor');
|
||||
const WsRequestor = require('../utils/ws-requestor');
|
||||
const {
|
||||
JAMBONES_INJECT_CONTENT,
|
||||
JAMBONES_EAGERLY_PRE_CACHE_AUDIO,
|
||||
AWS_REGION,
|
||||
} = require('../config');
|
||||
const BackgroundTaskManager = require('../utils/background-task-manager');
|
||||
@@ -1330,6 +1331,35 @@ Duration=${duration} `
|
||||
this.taskIdx = 0;
|
||||
}
|
||||
|
||||
_preCacheAudio(newTasks) {
|
||||
for (const task of newTasks) {
|
||||
if (task.name === TaskName.Config && task.hasSynthesizer) {
|
||||
/* if they change synthesizer settings don't try to precache */
|
||||
break;
|
||||
}
|
||||
if (task.name === TaskName.Say) {
|
||||
/* identify vendor language, voice, and label */
|
||||
const vendor = task.synthesizer.vendor && task.synthesizer.vendor !== 'default' ?
|
||||
task.synthesizer.vendor :
|
||||
this.speechSynthesisVendor;
|
||||
const language = task.synthesizer.language && task.synthesizer.language !== 'default' ?
|
||||
task.synthesizer.language :
|
||||
this.speechSynthesisLanguage ;
|
||||
const voice = task.synthesizer.voice && task.synthesizer.voice !== 'default' ?
|
||||
task.synthesizer.voice :
|
||||
this.speechSynthesisVoice;
|
||||
const label = task.synthesizer.label && task.synthesizer.label !== 'default' ?
|
||||
task.synthesizer.label :
|
||||
this.speechSynthesisLabel;
|
||||
|
||||
this.logger.info({vendor, language, voice, label},
|
||||
'CallSession:_preCacheAudio - precaching audio for future prompt');
|
||||
task._synthesizeWithSpecificVendor(this, this.ep, {vendor, language, voice, label, preCache: true})
|
||||
.catch((err) => this.logger.error(err, 'CallSession:_preCacheAudio - error precaching audio'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append tasks to the current execution stack UNLESS there is a gather in the stack.
|
||||
* in that case, insert the tasks before the gather AND if the tasks include
|
||||
@@ -1387,10 +1417,12 @@ Duration=${duration} `
|
||||
this.replaceApplication(t);
|
||||
}
|
||||
else if (JAMBONES_INJECT_CONTENT) {
|
||||
if (JAMBONES_EAGERLY_PRE_CACHE_AUDIO) this._preCacheAudio(t);
|
||||
this._injectTasks(t);
|
||||
this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
|
||||
}
|
||||
else {
|
||||
if (JAMBONES_EAGERLY_PRE_CACHE_AUDIO) this._preCacheAudio(t);
|
||||
this.tasks.push(...t);
|
||||
this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user