admin管理员组文章数量:1279090
I am using React.js along with the Web Speech API's SpeechRecognition, however, it does not work and I get the error "ReferenceError: SpeechRecognition is not defined." The code I am using is directly from the SpeechRecognition documentation:
const SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
const recognition = new SpeechRecognition();
The first line causes the error, but without it, the second line will cause the same error. How can I fix this?
I am using React.js along with the Web Speech API's SpeechRecognition, however, it does not work and I get the error "ReferenceError: SpeechRecognition is not defined." The code I am using is directly from the SpeechRecognition documentation:
const SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
const recognition = new SpeechRecognition();
The first line causes the error, but without it, the second line will cause the same error. How can I fix this?
Share Improve this question asked Oct 3, 2020 at 5:25 Anchey PengAnchey Peng 1131 gold badge1 silver badge6 bronze badges2 Answers
Reset to default 11try window.SpeechRecognition || window.webkitSpeechRecognition;
See Using the Web Speech API for further explanation why you need the window.
prefix.
Try this:
Instead of
const recognition = new SpeechRecognition();
Write:
const recognition = new speechRecognition();
This helped me!
本文标签: javascriptWeb Speech API SpeechRecognition not defined when using ReactjsStack Overflow
版权声明:本文标题:javascript - Web Speech API SpeechRecognition not defined when using React.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741261238a2367663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论