首页 > 解决方案 > iOS13 Safari WebSpeechApi 错误:SpeechSynthesisUtterance 不会使用提供的语言环境

问题描述

iOS 13(Safari 和 WkWebView)中似乎存在一个错误,它使 iOS 使用设备语言语音,并且无法通过查看 SpeechSynthesisUtterance 中提供的“语言”来找到合适的语音。

我通过自己设置合适的声音解决了这个问题。

这在其他浏览器/平台中不需要(例如 macOS Safari、iOS < 13、Chrome 等)

       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';
       });
  }

标签: iossafarimobile-safariios13webspeech-api

解决方案


似乎需要在 iOS13 的 SpeechSynthesisUtterance 上明确设置语音,因为语言环境不用于查找语音。


推荐阅读