// 创建一个新的SpeechRecognition对象
var recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition || window.mozSpeechRecognition || window.msSpeechRecognition)();
recognition.lang = 'en-US'; // 设置语言
recognition.interimResults = false; // 设置是否返回临时结果
recognition.maxAlternatives = 1; // 设置返回的最大替代词数量
// 当识别到语音结束时,返回结果
recognition.onresult = function(event) {
console.log('You said: ', event.results[0][0].transcript);
};
// 开始语音识别
recognition.start();
demo