const recognitaion = new SpeechRecognition();
recogntion.interimResults = true;
let p = document.createElement('p');
const words = document.querySelector('.words');
words.appendChild(p);
recognition.addEventListener('result', e =>{
const transcript=Array.from(e.results)
.map(results => results[0])
.map(results => result.transcript)
.join('')
p.textContent = transcript;
if(e.result[0].isFinal){
p = document.createElement('p');
words.appendChild(p);
}
if(transcript.includes('get the weater')){
console.log("getting the weater")
}
})
recognition.addEventListener('end',recognition.start)
recognition.start();
參考資料來源: