diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-02-24 21:31:14 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-02-24 21:31:14 -0800 |
commit | d32f4def0eeed1599857bc04c973337a2a13dd8b (patch) | |
tree | 61149656f361dd2d9998d67d68249dc184b73fbb /ext/mixed/js/audio.js | |
parent | 0c5b9b1fa1599cbf769d96cdebc226310f9dd8bc (diff) | |
parent | 706c3edcffb0078d71fd5b58775f16cf5fc1205b (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/mixed/js/audio.js')
-rw-r--r-- | ext/mixed/js/audio.js | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js index b0c5fa82..b5a025be 100644 --- a/ext/mixed/js/audio.js +++ b/ext/mixed/js/audio.js @@ -16,6 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/*global apiAudioGetUrl*/ class TextToSpeechAudio { constructor(text, voice) { @@ -53,7 +54,6 @@ class TextToSpeechAudio { speechSynthesis.cancel(); speechSynthesis.speak(this._utterance); - } catch (e) { // NOP } @@ -71,21 +71,16 @@ class TextToSpeechAudio { const m = /^tts:[^#?]*\?([^#]*)/.exec(ttsUri); if (m === null) { return null; } - const searchParameters = {}; - for (const group of m[1].split('&')) { - const sep = group.indexOf('='); - if (sep < 0) { continue; } - searchParameters[decodeURIComponent(group.substring(0, sep))] = decodeURIComponent(group.substring(sep + 1)); - } - - if (!searchParameters.text) { return null; } + const searchParameters = new URLSearchParams(m[1]); + const text = searchParameters.get('text'); + let voice = searchParameters.get('voice'); + if (text === null || voice === null) { return null; } - const voice = audioGetTextToSpeechVoice(searchParameters.voice); + voice = audioGetTextToSpeechVoice(voice); if (voice === null) { return null; } - return new TextToSpeechAudio(searchParameters.text, voice); + return new TextToSpeechAudio(text, voice); } - } function audioGetFromUrl(url, willDownload) { @@ -113,8 +108,11 @@ function audioGetFromUrl(url, willDownload) { async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) { const key = `${expression.expression}:${expression.reading}`; - if (cache !== null && hasOwn(cache, expression)) { - return cache[key]; + if (cache !== null) { + const cacheValue = cache.get(expression); + if (typeof cacheValue !== 'undefined') { + return cacheValue; + } } for (let i = 0, ii = sources.length; i < ii; ++i) { @@ -132,7 +130,7 @@ async function audioGetFromSources(expression, sources, optionsContext, willDown } const result = {audio, url, source}; if (cache !== null) { - cache[key] = result; + cache.set(key, result); } return result; } catch (e) { |