Skip to content

Commit

Permalink
fixed speech2text
Browse files Browse the repository at this point in the history
  • Loading branch information
SebA-R committed Jul 18, 2023
1 parent ff8224e commit e642b0e
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions static/speechtotext.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
const s2t_button = document.getElementById("speech_to_text");
const textarea = document.getElementById("input_field");
let isActive = false;
let recognition;

function SpeechToText() {
s2t_button.addEventListener("click", {once: true}, (e) => {
e.preventDefault();
s2t_button.firstElementChild.style = "filter: invert(75%) sepia(17%) saturate(7001%) hue-rotate(297deg) brightness(102%) contrast(101%);"
const recognition = new webkitSpeechRecognition();
function activateSpeechToText() {
isActive = true;
s2t_button.firstElementChild.style = "filter: invert(75%) sepia(17%) saturate(7001%) hue-rotate(297deg) brightness(102%) contrast(101%);";
recognition = new webkitSpeechRecognition();

s2t_button.addEventListener("click", {once: true}, (e) => {
s2t_button.firstElementChild.style = "none";
recognition.stop();
return SpeechToText();
});

recognition.onresult = function(event) {
s2t_button.firstElementChild.style = "none";
const transcript = event.results[event.results.length - 1][0].transcript.trim();
textarea.value += transcript;
};

recognition.onend = (event) => {
s2t_button.firstElementChild.style = "none";
}
recognition.onresult = function(event) {
const transcript = event.results[event.results.length - 1][0].transcript.trim();
textarea.value += transcript;
s2t_button.firstElementChild.style = "none";
};

recognition.start();
}

recognition.start();
});
function deactivateSpeechToText() {
isActive = false;
s2t_button.firstElementChild.style = "none";
recognition.stop();
}

SpeechToText();
s2t_button.addEventListener("click", function(e) {
e.preventDefault();
if (isActive) {
deactivateSpeechToText();
} else {
activateSpeechToText();
}
});

0 comments on commit e642b0e

Please sign in to comment.