Return index of the source instead of the source value
This commit is contained in:
parent
f50aee1021
commit
7eb7c88394
@ -85,13 +85,15 @@ class AudioSystem {
|
|||||||
const cacheValue = this._cache.get(key);
|
const cacheValue = this._cache.get(key);
|
||||||
if (typeof cacheValue !== 'undefined') {
|
if (typeof cacheValue !== 'undefined') {
|
||||||
const {audio, uri, source} = cacheValue;
|
const {audio, uri, source} = cacheValue;
|
||||||
if (sources.includes(source)) {
|
const index = sources.indexOf(source);
|
||||||
return {audio, uri, source};
|
if (index >= 0) {
|
||||||
|
return {audio, uri, index};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const source of sources) {
|
for (let i = 0, ii = sources.length; i < ii; ++i) {
|
||||||
|
const source = sources[i];
|
||||||
const uri = await this._getAudioUri(definition, source, details);
|
const uri = await this._getAudioUri(definition, source, details);
|
||||||
if (uri === null) { continue; }
|
if (uri === null) { continue; }
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ class AudioSystem {
|
|||||||
this._cacheCheck();
|
this._cacheCheck();
|
||||||
this._cache.set(key, {audio, uri, source});
|
this._cache.set(key, {audio, uri, source});
|
||||||
}
|
}
|
||||||
return {audio, uri, source};
|
return {audio, uri, index: i};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
|
@ -796,11 +796,12 @@ class Display {
|
|||||||
this.audioPlaying = null;
|
this.audioPlaying = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let audio, source, info;
|
let audio, info;
|
||||||
try {
|
try {
|
||||||
const {sources, textToSpeechVoice, customSourceUrl} = this.options.audio;
|
const {sources, textToSpeechVoice, customSourceUrl} = this.options.audio;
|
||||||
({audio, source} = await this.audioSystem.getDefinitionAudio(expression, sources, {textToSpeechVoice, customSourceUrl}));
|
let index;
|
||||||
info = `From source ${1 + sources.indexOf(source)}: ${source}`;
|
({audio, index} = await this.audioSystem.getDefinitionAudio(expression, sources, {textToSpeechVoice, customSourceUrl}));
|
||||||
|
info = `From source ${1 + index}: ${sources[index]}`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (this.audioFallback === null) {
|
if (this.audioFallback === null) {
|
||||||
this.audioFallback = new Audio('/mixed/mp3/button.mp3');
|
this.audioFallback = new Audio('/mixed/mp3/button.mp3');
|
||||||
|
Loading…
Reference in New Issue
Block a user