Search code examples
iossafarimobile-safariios13webspeech-api

iOS13 Safari WebSpeechApi Bug: SpeechSynthesisUtterance won't use provided locale


There seems to be a bug in iOS 13 (Safari and WkWebView) that makes iOS use the device language voice and not find a suitable voice by looking at the 'lang' provided in the SpeechSynthesisUtterance.

I worked around the issue by setting a suitable voice myself.

This is not needed in other browsers/platforms (eg macOS Safari, iOS < 13, Chrome etc.)

       this._getUtteranceRate().then((rate) => {
          let utterance = new SpeechSynthesisUtterance(words);
          utterance.rate = rate;
          utterance.lang = 'sv-SE';
          utterance.voice = this.voice; //IOS13 fix
          window.speechSynthesis.speak(utterance);
        });


       window.speechSynthesis.onvoiceschanged = () => {
         this.setVoice();
       }

       setVoice() {
            this.voice = window.speechSynthesis.getVoices().find((voice) => {
              return voice.lang === 'sv-SE';
       });
  }


Solution

  • It seems one needs to set the voice explicitly on the SpeechSynthesisUtterance for iOS13, as the locale is not used to find the voice.