research + download + storage wip

master
km0 3 years ago
parent e1560fee5f
commit 7369b38357

@ -10,6 +10,7 @@
</head>
<body>
<button id="save">Save</button>
<button id="reset">Reset</button>
<div id="result"></div>
<div id="process"></div>
</body>

@ -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 = "";
speechRecognizer.addEventListener("end", function () {
// LISTENERS
// 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"));
});

Binary file not shown.
Loading…
Cancel
Save