// 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
// GLOBAL VARIABLES
letallTheInterim="";
letinterimTranscripts ="";// Variable for interim results, the Speech-to-text try different worlds before to give us the most correct one.
letfinalTranscripts="";
letallTheInterim ="";// Variable to store *all* the interim results
letinterimTranscripts="";
letfinalTranscripts ="";// Variable for the... final transcripts
letspeech=document.getElementById("result");
// To define bridges to the html file:
letprocess=document.getElementById("process");
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
// TEXT STORAGE
lettextStorage=localStorage.getItem("speech");
lettextStorage=localStorage.getItem("speech");// This define where to save the results.
speech.innerHTML=textStorage;
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
// 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;
interimTranscripts+=transcript;
allTheInterim+=`<span style="opacity: ${
allTheInterim+=`<span style="opacity: ${
event.results[i][0].confidence+0.3
event.results[i][0].confidence+0.3
@ -102,9 +116,12 @@ function startConverting() {
textStorage=final;
textStorage=final;
console.log(textStorage);
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";
speech.innerHTML="At the moment this works only in Chrome, sorry";