From bfdca0509193e57d10832cf522d9bf2d3de968b9 Mon Sep 17 00:00:00 2001 From: Matt Flax Date: Wed, 14 May 2025 13:51:11 +1000 Subject: [PATCH] auto transcription with led changes --- aider/gui_speech_to_text.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/aider/gui_speech_to_text.js b/aider/gui_speech_to_text.js index a7201b191..81b08ad56 100644 --- a/aider/gui_speech_to_text.js +++ b/aider/gui_speech_to_text.js @@ -113,14 +113,17 @@ if (isListening) return; isListening = true; - led.style.backgroundColor = 'lime'; - recognition.start(); - // Show stop button if auto transcribe is enabled + // Set initial LED color based on auto-transcribe mode if (autoTranscribe.checked) { + led.style.backgroundColor = 'red'; // Red when waiting for voice stopButton.style.display = 'inline-block'; recognition.continuous = true; + } else { + led.style.backgroundColor = 'lime'; } + + recognition.start(); }); // Setup stop button click handler @@ -136,14 +139,24 @@ recognition.onspeechstart = function() { console.log('Speech detected'); if (autoTranscribe.checked) { - led.style.backgroundColor = 'red'; + led.style.backgroundColor = 'green'; // Green when voice is detected + } + }; + + // Handle speech end + recognition.onspeechend = function() { + console.log('Speech ended'); + if (autoTranscribe.checked && isListening) { + led.style.backgroundColor = 'red'; // Red when waiting for voice } }; // Combined event handler function for speech recognition events function handleSpeechEvent(eventType, event) { if (eventType === 'result') { - const transcript = event.results[0][0].transcript; + // Get the latest transcript + const resultIndex = event.resultIndex; + const transcript = event.results[resultIndex][0].transcript; // Try to populate the chat input directly const success = populateChatInput(transcript); @@ -153,6 +166,8 @@ // If not in auto-transcribe mode, reset the LED if (!autoTranscribe.checked) { led.style.backgroundColor = 'gray'; + } else { + led.style.backgroundColor = 'red'; // Back to red after processing result } } else if (eventType === 'error') {