aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/api.js4
-rw-r--r--ext/mixed/js/audio-system.js21
-rw-r--r--ext/mixed/js/display.js17
3 files changed, 23 insertions, 19 deletions
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js
index 7080d93a..c97dc687 100644
--- a/ext/mixed/js/api.js
+++ b/ext/mixed/js/api.js
@@ -64,8 +64,8 @@ function apiTemplateRender(template, data) {
return _apiInvoke('templateRender', {data, template});
}
-function apiAudioGetUri(definition, source, optionsContext) {
- return _apiInvoke('audioGetUri', {definition, source, optionsContext});
+function apiAudioGetUri(definition, source, details) {
+ return _apiInvoke('audioGetUri', {definition, source, details});
}
function apiCommandExec(command, params) {
diff --git a/ext/mixed/js/audio-system.js b/ext/mixed/js/audio-system.js
index 45b733fc..574ad3dc 100644
--- a/ext/mixed/js/audio-system.js
+++ b/ext/mixed/js/audio-system.js
@@ -66,10 +66,10 @@ class TextToSpeechAudio {
}
class AudioSystem {
- constructor({getAudioUri}) {
+ constructor({audioUriBuilder}) {
this._cache = new Map();
this._cacheSizeMaximum = 32;
- this._getAudioUri = getAudioUri;
+ this._audioUriBuilder = audioUriBuilder;
if (typeof speechSynthesis !== 'undefined') {
// speechSynthesis.getVoices() will not be populated unless some API call is made.
@@ -90,7 +90,7 @@ class AudioSystem {
if (uri === null) { continue; }
try {
- const audio = await this._createAudio(uri, details);
+ const audio = await this._createAudio(uri);
this._cacheCheck();
this._cache.set(key, {audio, uri, source});
return {audio, uri, source};
@@ -114,20 +114,23 @@ class AudioSystem {
// NOP
}
- async _createAudio(uri, details) {
+ async _createAudio(uri) {
const ttsParameters = this._getTextToSpeechParameters(uri);
if (ttsParameters !== null) {
- if (typeof details === 'object' && details !== null) {
- if (details.tts === false) {
- throw new Error('Text-to-speech not permitted');
- }
- }
return this.createTextToSpeechAudio(ttsParameters);
}
return await this._createAudioFromUrl(uri);
}
+ _getAudioUri(definition, source, details) {
+ return (
+ this._audioUriBuilder !== null ?
+ this._audioUriBuilder.getUri(definition, source, details) :
+ null
+ );
+ }
+
_createAudioFromUrl(url) {
return new Promise((resolve, reject) => {
const audio = new Audio(url);
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 63687dc2..7f3ba859 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -45,7 +45,13 @@ class Display {
this.index = 0;
this.audioPlaying = null;
this.audioFallback = null;
- this.audioSystem = new AudioSystem({getAudioUri: this._getAudioUri.bind(this)});
+ this.audioSystem = new AudioSystem({
+ audioUriBuilder: {
+ async getUri(definition, source, details) {
+ return await apiAudioGetUri(definition, source, details);
+ }
+ }
+ });
this.styleNode = null;
this.eventListeners = new EventListenerCollection();
@@ -789,10 +795,10 @@ class Display {
this.audioPlaying = null;
}
- const sources = this.options.audio.sources;
let audio, source, info;
try {
- ({audio, source} = await this.audioSystem.getDefinitionAudio(expression, sources));
+ const {sources, textToSpeechVoice, customSourceUrl} = this.options.audio;
+ ({audio, source} = await this.audioSystem.getDefinitionAudio(expression, sources, {textToSpeechVoice, customSourceUrl}));
info = `From source ${1 + sources.indexOf(source)}: ${source}`;
} catch (e) {
if (this.audioFallback === null) {
@@ -947,9 +953,4 @@ class Display {
}
};
}
-
- async _getAudioUri(definition, source) {
- const optionsContext = this.getOptionsContext();
- return await apiAudioGetUri(definition, source, optionsContext);
- }
}