- Using google api's to transform voice to text.
- Method of window object we going to make it standard with lines below
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
- Make an instance
const recognition = new SpeechRecognition();
- Set language
Default on 'en-US'
recognition.lang = "fa-IR";
- This line of code couses to fetch result one by one at moment
recognition.interimResults = true;
- Start by calling start method
recognition.start();
- We connect all results by join() method then like below
let transcript = Array.from(event.results)
.map((el) => {
return el[0];
})
.map((el) => {
return el.transcript;
})
.join(" ");
- Then we have string so we can explore it with includes() method, I mean
if (result.includes("Order")) {
// Remove Order Text From Screen
result = '';
// What You Want To Do On This Order
RelatedOrderMethod();
}
- Example :
if (transcript.includes("jump next line")) {
// Remove Order Text From Screen
transcript = '';
// Action
p = document.createElement("p");
textPlace.appendChild(p);
}
- GitHub Link
- Mohammad Saadati