使用麦克风输入意外结束
Unexpected End Of Input Using Microphone
我正在使用 SpeechRecognition 在我的一个程序中使用麦克风。
Chrome 控制台在最后说:输入意外结束
const speechRecognition =
window.webkitSpeechRecognition /*Chrome*/ ||
window.SpeechRecognition;/*Firefox...*/
function startListening() {
const recog = new speechRecognition
recog.start();
recog.onstart = console.log("Started Listening..");
recog.onresult = function (data) {
handleResults(data);
};
//'data' comes from 'onresult'
function handleResults(data) {
let text = data.result[0][0].transcript;
console.log(text);
}
// Call Function On Load
window.addEventListener('DOMContentLoaded', startListening());
您收到意外结束输入错误,因为您没有正确关闭 startListening 函数
function startListening() {
const recog = new speechRecognition
recog.start();
recog.onstart = console.log("Started Listening..");
recog.onresult = function (data) {
handleResults(data);
}
} // <-- this is missing in your code
我正在使用 SpeechRecognition 在我的一个程序中使用麦克风。
Chrome 控制台在最后说:输入意外结束
const speechRecognition =
window.webkitSpeechRecognition /*Chrome*/ ||
window.SpeechRecognition;/*Firefox...*/
function startListening() {
const recog = new speechRecognition
recog.start();
recog.onstart = console.log("Started Listening..");
recog.onresult = function (data) {
handleResults(data);
};
//'data' comes from 'onresult'
function handleResults(data) {
let text = data.result[0][0].transcript;
console.log(text);
}
// Call Function On Load
window.addEventListener('DOMContentLoaded', startListening());
您收到意外结束输入错误,因为您没有正确关闭 startListening 函数
function startListening() {
const recog = new speechRecognition
recog.start();
recog.onstart = console.log("Started Listening..");
recog.onresult = function (data) {
handleResults(data);
}
} // <-- this is missing in your code