diff options
Diffstat (limited to 'g4f')
-rw-r--r-- | g4f/gui/client/static/js/chat.v1.js | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 8933b442..7f4011a2 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -1074,7 +1074,7 @@ async function load_version() { } setTimeout(load_version, 2000); -for (const el of [imageInput, cameraInput]) { +[imageInput, cameraInput].forEach((el) => { el.addEventListener('click', async () => { el.value = ''; if (imageInput.dataset.src) { @@ -1082,7 +1082,7 @@ for (const el of [imageInput, cameraInput]) { delete imageInput.dataset.src } }); -} +}); fileInput.addEventListener('click', async (event) => { fileInput.value = ''; @@ -1261,31 +1261,26 @@ if (SpeechRecognition) { recognition.interimResults = true; recognition.maxAlternatives = 1; - function may_stop() { - if (microLabel.classList.contains("recognition")) { - recognition.stop(); - } - } - let startValue; - let timeoutHandle; + let shouldStop; let lastDebounceTranscript; recognition.onstart = function() { microLabel.classList.add("recognition"); startValue = messageInput.value; + shouldStop = false; lastDebounceTranscript = ""; - timeoutHandle = window.setTimeout(may_stop, 10000); }; recognition.onend = function() { - microLabel.classList.remove("recognition"); - messageInput.focus(); + if (shouldStop) { + messageInput.focus(); + } else { + recognition.start(); + } }; recognition.onresult = function(event) { if (!event.results) { return; } - window.clearTimeout(timeoutHandle); - let result = event.results[event.resultIndex]; let isFinal = result.isFinal && (result[0].confidence > 0); let transcript = result[0].transcript; @@ -1303,14 +1298,13 @@ if (SpeechRecognition) { messageInput.style.height = messageInput.scrollHeight + "px"; messageInput.scrollTop = messageInput.scrollHeight; } - - timeoutHandle = window.setTimeout(may_stop, transcript ? 10000 : 8000); }; microLabel.addEventListener("click", () => { if (microLabel.classList.contains("recognition")) { - window.clearTimeout(timeoutHandle); + shouldStop = true; recognition.stop(); + microLabel.classList.remove("recognition"); } else { const lang = document.getElementById("recognition-language")?.value; recognition.lang = lang || navigator.language; |