|
|
@ -1,36 +1,85 @@
|
|
|
|
let recognition = new webkitSpeechRecognition() || new SpeechRecognition();
|
|
|
|
// GLOBAL VARIABLES
|
|
|
|
|
|
|
|
|
|
|
|
let textStorage = localStorage.getItem("speech");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let allTheInterim = "";
|
|
|
|
let allTheInterim = "";
|
|
|
|
|
|
|
|
let finalTranscripts = "";
|
|
|
|
|
|
|
|
let interimTranscripts = "";
|
|
|
|
|
|
|
|
|
|
|
|
let speech = document.getElementById("result");
|
|
|
|
let speech = document.getElementById("result");
|
|
|
|
let process = document.getElementById("process");
|
|
|
|
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();
|
|
|
|
startConverting();
|
|
|
|
|
|
|
|
|
|
|
|
function startConverting() {
|
|
|
|
function startConverting() {
|
|
|
|
if ("webkitSpeechRecognition" in window) {
|
|
|
|
if ("webkitSpeechRecognition" in window) {
|
|
|
|
let speechRecognizer = new webkitSpeechRecognition() || new SpeechRecognition();
|
|
|
|
let speechRecognizer = new webkitSpeechRecognition() || new SpeechRecognition();
|
|
|
|
speechRecognizer.continuous = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
speechRecognizer.continuous = true;
|
|
|
|
speechRecognizer.interimResults = true;
|
|
|
|
speechRecognizer.interimResults = true;
|
|
|
|
|
|
|
|
|
|
|
|
speechRecognizer.lang = "en-US";
|
|
|
|
speechRecognizer.lang = "en-US";
|
|
|
|
speechRecognizer.start();
|
|
|
|
speechRecognizer.start();
|
|
|
|
|
|
|
|
|
|
|
|
let finalTranscripts = "";
|
|
|
|
finalTranscripts = "";
|
|
|
|
|
|
|
|
|
|
|
|
speechRecognizer.addEventListener("end", function () {
|
|
|
|
// LISTENERS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ON END
|
|
|
|
|
|
|
|
speechRecognizer.onend = function () {
|
|
|
|
console.log("Speech recognition service disconnected");
|
|
|
|
console.log("Speech recognition service disconnected");
|
|
|
|
speechRecognizer.start();
|
|
|
|
speechRecognizer.start();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ON SOUND START
|
|
|
|
speechRecognizer.onsoundstart = function () {
|
|
|
|
speechRecognizer.onsoundstart = function () {
|
|
|
|
console.log("Some sound is being received");
|
|
|
|
console.log("Some sound is being received");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ON ERROR
|
|
|
|
|
|
|
|
speechRecognizer.onerror = function (event) {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ON RESULT
|
|
|
|
speechRecognizer.onresult = function (event) {
|
|
|
|
speechRecognizer.onresult = function (event) {
|
|
|
|
let interimTranscripts = "";
|
|
|
|
interimTranscripts = "";
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = event.resultIndex; i < event.results.length; i++) {
|
|
|
|
for (let i = event.resultIndex; i < event.results.length; i++) {
|
|
|
|
let transcript = event.results[i][0].transcript;
|
|
|
|
let transcript = event.results[i][0].transcript;
|
|
|
@ -51,18 +100,11 @@ function startConverting() {
|
|
|
|
|
|
|
|
|
|
|
|
speech.innerHTML = final;
|
|
|
|
speech.innerHTML = final;
|
|
|
|
|
|
|
|
|
|
|
|
textStorage += finalTranscripts;
|
|
|
|
textStorage = final;
|
|
|
|
|
|
|
|
console.log(textStorage);
|
|
|
|
localStorage.setItem("speech", textStorage);
|
|
|
|
localStorage.setItem("speech", final);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
speechRecognizer.onerror = function (event) {};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} 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"));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|