summaryrefslogtreecommitdiff
path: root/ext/js/media/audio-system.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/media/audio-system.js')
-rw-r--r--ext/js/media/audio-system.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/js/media/audio-system.js b/ext/js/media/audio-system.js
index cf63511f..cc2bcfc0 100644
--- a/ext/js/media/audio-system.js
+++ b/ext/js/media/audio-system.js
@@ -19,18 +19,20 @@
* TextToSpeechAudio
*/
-class AudioSystem {
+class AudioSystem extends EventDispatcher {
constructor() {
+ super();
this._fallbackAudio = null;
}
prepare() {
// speechSynthesis.getVoices() will not be populated unless some API call is made.
- if (typeof speechSynthesis === 'undefined') { return; }
-
- const eventListeners = new EventListenerCollection();
- const onVoicesChanged = () => { eventListeners.removeAllEventListeners(); };
- eventListeners.addEventListener(speechSynthesis, 'voiceschanged', onVoicesChanged, false);
+ if (
+ typeof speechSynthesis !== 'undefined' &&
+ typeof speechSynthesis.addEventListener === 'function'
+ ) {
+ speechSynthesis.addEventListener('voiceschanged', this._onVoicesChanged.bind(this), false);
+ }
}
getFallbackAudio() {
@@ -64,6 +66,10 @@ class AudioSystem {
// Private
+ _onVoicesChanged(e) {
+ this.trigger('voiceschanged', e);
+ }
+
_isAudioValid(audio, source) {
switch (source) {
case 'jpod101':