diff options
author | abc <98614666+xtekky@users.noreply.github.com> | 2024-04-14 03:37:17 +0200 |
---|---|---|
committer | abc <98614666+xtekky@users.noreply.github.com> | 2024-04-14 03:37:17 +0200 |
commit | 46dcf0855426cb3837be2b0d50bdfeebda5014da (patch) | |
tree | 4c1549f3c164dd2ae3653b58efd5cc7f000fe8d3 | |
parent | stytch auth udpdate for provider (diff) | |
parent | Fix SpeechRecognition on Phone (diff) | |
download | gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.tar gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.tar.gz gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.tar.bz2 gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.tar.lz gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.tar.xz gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.tar.zst gpt4free-46dcf0855426cb3837be2b0d50bdfeebda5014da.zip |
-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; |