commit 94d72d3ced4a141182c7580ab927558554836ed2 Author: lzzfnc Date: Thu Sep 30 21:07:39 2021 +0200 init diff --git a/index.html b/index.html new file mode 100644 index 0000000..2f06af5 --- /dev/null +++ b/index.html @@ -0,0 +1,16 @@ + + + + + + + Document + + + + + +
+
+ + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..de0296a --- /dev/null +++ b/index.js @@ -0,0 +1,68 @@ +let recognition = new webkitSpeechRecognition() || new SpeechRecognition(); + +let textStorage = localStorage.getItem("speech"); + +let allTheInterim = ""; + +let speech = document.getElementById("result"); +let process = document.getElementById("process"); +startConverting(); + +function startConverting() { + if ("webkitSpeechRecognition" in window) { + let speechRecognizer = new webkitSpeechRecognition() || new SpeechRecognition(); + speechRecognizer.continuous = true; + + speechRecognizer.interimResults = true; + + speechRecognizer.lang = "en-US"; + speechRecognizer.start(); + + let finalTranscripts = ""; + + speechRecognizer.addEventListener("end", function () { + console.log("Speech recognition service disconnected"); + speechRecognizer.start(); + }); + + speechRecognizer.onsoundstart = function () { + console.log("Some sound is being received"); + }; + + speechRecognizer.onresult = function (event) { + let interimTranscripts = ""; + + for (let i = event.resultIndex; i < event.results.length; i++) { + let transcript = event.results[i][0].transcript; + // console.log(event.results[i][0]); + transcript.replace("\n", "
"); + if (event.results[i].isFinal) { + finalTranscripts += transcript; + } else { + interimTranscripts += transcript; + allTheInterim += `${interimTranscripts} `; + } + } + process.innerHTML = allTheInterim; + let final = + finalTranscripts + '' + interimTranscripts + ""; + + speech.innerHTML = final; + + textStorage += finalTranscripts; + + localStorage.setItem("speech", textStorage); + }; + speechRecognizer.onerror = function (event) {}; + } else { + speech.innerHTML = "oi va su chrome pirla"; + } +} +let saveButton = document.getElementById("save"); + +saveButton.addEventListener("click", () => { + console.log("we"); + console.log(localStorage.getItem("speech")); +}); diff --git a/style.css b/style.css new file mode 100644 index 0000000..2759610 --- /dev/null +++ b/style.css @@ -0,0 +1,15 @@ +.interim { + color: #999; +} + +#result { + max-width: 800px; + margin: 0 auto; + font-size: 2rem; +} + +#process { + max-width: 800px; + margin: 0 auto; + margin-top: 50px; +}