文本到语音api上的错误:ReferenceError:语音合成未定义

问题描述 投票:0回答:1

我正在使用类星体框架(正在vue上工作并且可以通过cordova在移动设备上进行编译)编写程序。我在移动设备上运行时遇到一些问题。这是功能:

    activateAudio: function(){
      try{
        speechSynthesis.speak(new SpeechSynthesisUtterance('hey'))        
      }catch(e){
        alert(e)
      }

当我运行此代码时,我会收到此警报:

ReferenceError:语音合成未定义

我还尝试将window放在变量之前。为什么会发生此错误?

之后的图书馆:https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance/SpeechSynthesisUtterance

javascript cordova vue.js text-to-speech quasar-framework
1个回答
0
投票

似乎您正在尝试在非浏览器JS环境中使用Web Speech API。除非您的JS环境实现了Web Speech API,否则您需要找到JS环境is支持的一些替代API。

鉴于您正在使用Cordova,您可能应该尝试使用类似以下的内容:cordova-plugin-tts

© www.soinside.com 2019 - 2024. All rights reserved.