From 864fcab1ce5c762df16058102d7cb388394321a4 Mon Sep 17 00:00:00 2001 From: aewing Date: Fri, 16 Jan 2026 02:42:04 +0000 Subject: [PATCH] Fix voice search for notes list - Fix 'already started' error in speech recognition - Add toggle behavior for voice button (start/stop) - Improve transcript handling for single words - Show interim results in real-time as user speaks - Add detailed console logging for debugging - Ensure search triggers on final results - Search already covers both title and body fields --- index.html | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 9352740..d1a78ce 100644 --- a/index.html +++ b/index.html @@ -3064,6 +3064,12 @@ const searchVoiceBtn = document.getElementById('searchVoiceBtn'); function startSearchVoice() { + // If already recognizing, stop it instead (toggle behavior) + if (isSearchRecognizing) { + stopSearchVoice(); + return; + } + if (!searchRecognition) { const SR = window.SpeechRecognition || window.webkitSpeechRecognition; if (!SR) { @@ -3077,16 +3083,32 @@ searchRecognition.onresult = (event) => { let finalTranscript = ''; - for (let i = 0; i < event.results.length; i++) { + let interimTranscript = ''; + + for (let i = event.results.length - 1; i >= 0; i--) { + const transcript = event.results[i][0].transcript; if (event.results[i].isFinal) { - finalTranscript += event.results[i][0].transcript + ' '; + finalTranscript += transcript + ' '; + } else { + interimTranscript += transcript; } } - if (finalTranscript) { - notesSearchInput.value = finalTranscript.trim(); - searchQuery = notesSearchInput.value; + + // Update with interim results for real-time feedback + const displayText = (finalTranscript + interimTranscript).trim(); + if (displayText) { + notesSearchInput.value = displayText; + console.log('Voice search input:', displayText); + } + + // Apply search when we have final results + if (finalTranscript.trim()) { + const finalText = finalTranscript.trim(); + searchQuery = finalText; + console.log('Voice search final query:', searchQuery); applySearch(); } + // auto-stop after 2s of silence clearTimeout(searchSilenceTimer); searchSilenceTimer = setTimeout(() => { @@ -3100,7 +3122,8 @@ searchVoiceBtn.classList.add('text-purple-600'); }; - searchRecognition.onerror = () => { + searchRecognition.onerror = (event) => { + console.error('Speech recognition error:', event.error); stopSearchVoice(); }; }