|
|
|
@ -1,36 +1,85 @@
|
|
|
|
|
let recognition = new webkitSpeechRecognition() || new SpeechRecognition();
|
|
|
|
|
|
|
|
|
|
let textStorage = localStorage.getItem("speech");
|
|
|
|
|
// GLOBAL VARIABLES
|
|
|
|
|
|
|
|
|
|
let allTheInterim = "";
|
|
|
|
|
let finalTranscripts = "";
|
|
|
|
|
let interimTranscripts = "";
|
|
|
|
|
|
|
|
|
|
let speech = document.getElementById("result");
|
|
|
|
|
let process = document.getElementById("process");
|
|
|
|
|
|
|
|
|
|
// TEXT STORAGE
|
|
|
|
|
|
|
|
|
|
let textStorage = localStorage.getItem("speech");
|
|
|
|
|
speech.innerHTML = textStorage;
|
|
|
|
|
|
|
|
|
|
// RESET STORAGE
|
|
|
|
|
|
|
|
|
|
let resetStorage = document.getElementById("reset");
|
|
|
|
|
|
|
|
|
|
resetStorage.addEventListener("click", () => {
|
|
|
|
|
// Reset everything
|
|
|
|
|
allTheInterim = "";
|
|
|
|
|
finalTranscripts = "";
|
|
|
|
|
interimTranscripts = "";
|
|
|
|
|
speech.innerHTML = "";
|
|
|
|
|
textStorage = "";
|
|
|
|
|
localStorage.setItem("speech", "");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// SAVE FILE
|
|
|
|
|
|
|
|
|
|
let saveButton = document.getElementById("save");
|
|
|
|
|
saveButton.addEventListener("click", () => {
|
|
|
|
|
download("speech.html", localStorage.getItem("speech"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function download(filename, text) {
|
|
|
|
|
var element = document.createElement("a");
|
|
|
|
|
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
|
|
|
|
|
element.setAttribute("download", filename);
|
|
|
|
|
|
|
|
|
|
element.style.display = "none";
|
|
|
|
|
document.body.appendChild(element);
|
|
|
|
|
|
|
|
|
|
element.click();
|
|
|
|
|
|
|
|
|
|
document.body.removeChild(element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// START LISTENING
|
|
|
|
|
|
|
|
|
|
startConverting();
|
|
|
|
|
|
|
|
|
|
function startConverting() {
|
|
|
|
|
if ("webkitSpeechRecognition" in window) {
|
|
|
|
|
let speechRecognizer = new webkitSpeechRecognition() || new SpeechRecognition();
|
|
|
|
|
speechRecognizer.continuous = true;
|
|
|
|
|
|
|
|
|
|
speechRecognizer.continuous = true;
|
|
|
|
|
speechRecognizer.interimResults = true;
|
|
|
|
|
|
|
|
|
|
speechRecognizer.lang = "en-US";
|
|
|
|
|
speechRecognizer.start();
|
|
|
|
|
|
|
|
|
|
let finalTranscripts = "";
|
|
|
|
|
finalTranscripts = "";
|
|
|
|
|
|
|
|
|
|
// LISTENERS
|
|
|
|
|
|
|
|
|
|
speechRecognizer.addEventListener("end", function () {
|
|
|
|
|
// ON END
|
|
|
|
|
speechRecognizer.onend = function () {
|
|
|
|
|
console.log("Speech recognition service disconnected");
|
|
|
|
|
speechRecognizer.start();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ON SOUND START
|
|
|
|
|
speechRecognizer.onsoundstart = function () {
|
|
|
|
|
console.log("Some sound is being received");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ON ERROR
|
|
|
|
|
speechRecognizer.onerror = function (event) {};
|
|
|
|
|
|
|
|
|
|
// ON RESULT
|
|
|
|
|
speechRecognizer.onresult = function (event) {
|
|
|
|
|
let interimTranscripts = "";
|
|
|
|
|
interimTranscripts = "";
|
|
|
|
|
|
|
|
|
|
for (let i = event.resultIndex; i < event.results.length; i++) {
|
|
|
|
|
let transcript = event.results[i][0].transcript;
|
|
|
|
@ -51,18 +100,11 @@ function startConverting() {
|
|
|
|
|
|
|
|
|
|
speech.innerHTML = final;
|
|
|
|
|
|
|
|
|
|
textStorage += finalTranscripts;
|
|
|
|
|
|
|
|
|
|
localStorage.setItem("speech", textStorage);
|
|
|
|
|
textStorage = final;
|
|
|
|
|
console.log(textStorage);
|
|
|
|
|
localStorage.setItem("speech", final);
|
|
|
|
|
};
|
|
|
|
|
speechRecognizer.onerror = function (event) {};
|
|
|
|
|
} else {
|
|
|
|
|
speech.innerHTML = "oi va su chrome pirla";
|
|
|
|
|
speech.innerHTML = "At the moment this works only in Chrome, sorry";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let saveButton = document.getElementById("save");
|
|
|
|
|
|
|
|
|
|
saveButton.addEventListener("click", () => {
|
|
|
|
|
console.log("we");
|
|
|
|
|
console.log(localStorage.getItem("speech"));
|
|
|
|
|
});
|
|
|
|
|