fix: Web API dictation stops while you are still talking (#31891)

With the Web API speech-to-text engine, the two-second silence timer only restarted when the browser finished a phrase. If you paused briefly and then kept talking for more than two seconds, dictation stopped mid-sentence. The timer now restarts whenever the browser hears speech, so dictation only stops after two seconds of silence.

Fixes #19727
This commit is contained in:
Classic298 2026-10-05 04:45:11 +02:00 • committed by GitHub
parent de9234a2b8
commit 1e834c09e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -308,6 +308,8 @@
// Set continuous to true for continuous recognition
speechRecognition.continuous = true;
// Interim results keep the inactivity timeout from firing mid-sentence
speechRecognition.interimResults = true;
// Set the timeout for turning off the recognition after inactivity (in milliseconds)
const inactivityTimeout = 2000; // 3 seconds
@ -323,9 +325,11 @@
// Handle recognized speech
console.log(event);
const transcript = event.results[Object.keys(event.results).length - 1][0].transcript;
transcription = `${transcription}${transcript}`;
for (const result of Array.from(event.results).slice(event.resultIndex)) {
if (result.isFinal) {
transcription = `${transcription}${result[0].transcript}`;
}
}
await tick();
document.getElementById('chat-input')?.focus();