Await and handle errors from audio.play()

This commit is contained in:
toasted-nutbread 2020-04-17 17:48:55 -04:00
parent 9fe7b9ad29
commit fcbfde506a
2 changed files with 9 additions and 2 deletions

View File

@ -40,7 +40,7 @@ class TextToSpeechAudio {
} }
} }
play() { async play() {
try { try {
if (this._utterance === null) { if (this._utterance === null) {
this._utterance = new SpeechSynthesisUtterance(this.text || ''); this._utterance = new SpeechSynthesisUtterance(this.text || '');

View File

@ -823,7 +823,14 @@ class Display {
this.audioPlaying = audio; this.audioPlaying = audio;
audio.currentTime = 0; audio.currentTime = 0;
audio.volume = this.options.audio.volume / 100.0; audio.volume = this.options.audio.volume / 100.0;
audio.play(); const playPromise = audio.play();
if (typeof playPromise !== 'undefined') {
try {
await playPromise;
} catch (e2) {
// NOP
}
}
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} finally { } finally {