According to the MDN docs one needs to wait in Chrome browsers for the onvoiceschanged event. This does not work on Firefox, therefore Mozilla suggests this approach:
var voices = [];
function populateVoiceList() {
voices = synth.getVoices();
// Now we have the voices.
}
populateVoiceList();
if (speechSynthesis.onvoiceschanged !== undefined) {
speechSynthesis.onvoiceschanged = populateVoiceList;
}
It would be nice if the SpeechSynthesisService.getVoices() would return a Promise or an Observable.
According to the MDN docs one needs to wait in Chrome browsers for the
onvoiceschanged
event. This does not work on Firefox, therefore Mozilla suggests this approach:It would be nice if the
SpeechSynthesisService.getVoices()
would return aPromise
or anObservable
.