// The tool we are gonna use is the "Web Speech API".
// What is an API?
// An API is a set of defined rules that explain how computers or applications communicate with one another.
// APIs sit between an application and the web server, acting as an intermediary layer that processes data transfer between systems.
// GLOBAL VARIABLES
letallTheInterim="";
letfinalTranscripts="";
letinterimTranscripts="";
letinterimTranscripts ="";// Variable for interim results, the Speech-to-text try different worlds before to give us the most correct one.
letallTheInterim ="";// Variable to store *all* the interim results
letfinalTranscripts ="";// Variable for the... final transcripts
letspeech=document.getElementById("result");
letprocess=document.getElementById("process");
// To define bridges to the html file:
letspeech=document.getElementById("result");// where to print the final result of the recognition
letprocess=document.getElementById("process");// and here the process, print the current sentence with interim results
// TEXT STORAGE
lettextStorage=localStorage.getItem("speech");
speech.innerHTML=textStorage;
lettextStorage=localStorage.getItem("speech");// This define where to save the results.
speech.innerHTML=textStorage;// LocalStorage is a type of web storage that allows you to access a local Storage object and store the data in the browser with no expiration date.
// RESET STORAGE
letresetStorage=document.getElementById("reset");
letresetStorage=document.getElementById("reset");// This will just reset, through a button, all the results got by that moment.
}else{// There are also shown the interim results and according to their "confidence" (the percentage of how much the word is correct) the color of each word could change
interimTranscripts+=transcript;
allTheInterim+=`<span style="opacity: ${
event.results[i][0].confidence+0.3
@ -102,9 +116,12 @@ function startConverting() {
textStorage=final;
console.log(textStorage);
localStorage.setItem("speech",final);
localStorage.setItem("speech",final);// Here is where is stored the recognized text in the Local Storage
};
}else{
}else{// Unfortunately this API works only on Chrome...
speech.innerHTML="At the moment this works only in Chrome, sorry";