Skip to content

Commit

Permalink
Fix SpeechRecognition on Phone
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus committed Apr 13, 2024
1 parent f323e88 commit cec2a10
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions g4f/gui/client/static/js/chat.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -1261,22 +1261,22 @@ if (SpeechRecognition) {
recognition.interimResults = true;
recognition.maxAlternatives = 1;

function may_stop() {
if (microLabel.classList.contains("recognition")) {
recognition.stop();
}
}

let startValue;
let shouldStop = false;
let lastDebounceTranscript;
recognition.onstart = function() {
microLabel.classList.add("recognition");
startValue = messageInput.value;
shouldStop = false;
lastDebounceTranscript = "";
};
recognition.onend = function() {
microLabel.classList.remove("recognition");
messageInput.focus();
if (shouldStop) {
microLabel.classList.remove("recognition");
messageInput.focus();
} else {
recognition.start();
}
};
recognition.onresult = function(event) {
if (!event.results) {
Expand All @@ -1303,6 +1303,7 @@ if (SpeechRecognition) {

microLabel.addEventListener("click", () => {
if (microLabel.classList.contains("recognition")) {
shouldStop = true;
recognition.stop();
} else {
const lang = document.getElementById("recognition-language")?.value;
Expand Down

0 comments on commit cec2a10

Please sign in to comment.