小编Anc*_*eng的帖子

使用 React.js 时未定义 Web Speech API SpeechRecognition

我将 React.js 与 Web Speech API 的 SpeechRecognition 一起使用,但是它不起作用,并且收到错误“ReferenceError:SpeechRecognition 未定义”。我使用的代码直接来自 SpeechRecognition 文档:

const SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
const recognition = new SpeechRecognition();
Run Code Online (Sandbox Code Playgroud)

第一行会导致错误,但如果没有它,第二行也会导致相同的错误。我怎样才能解决这个问题?

javascript speech-recognition reactjs webspeech-api

4
推荐指数
1
解决办法
1万
查看次数