mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
SpeechToText js : merge stop event handlers
This commit is contained in:
parent
edb51373b2
commit
323dadfe29
1 changed files with 20 additions and 15 deletions
|
@ -94,22 +94,27 @@
|
||||||
recognition.start();
|
recognition.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
recognition.onresult = function(event) {
|
// Combined event handler function for speech recognition events
|
||||||
const transcript = event.results[0][0].transcript;
|
function handleSpeechEvent(eventType, event) {
|
||||||
|
// Set LED back to gray for all events
|
||||||
led.style.backgroundColor = 'gray';
|
led.style.backgroundColor = 'gray';
|
||||||
|
|
||||||
// Try to populate the chat input directly
|
if (eventType === 'result') {
|
||||||
const success = populateChatInput(transcript);
|
const transcript = event.results[0][0].transcript;
|
||||||
if (!success)
|
|
||||||
console.error('populateChatInput failed');
|
// Try to populate the chat input directly
|
||||||
};
|
const success = populateChatInput(transcript);
|
||||||
|
if (!success)
|
||||||
|
console.error('populateChatInput failed');
|
||||||
|
}
|
||||||
|
else if (eventType === 'error') {
|
||||||
|
console.error('Speech recognition error', event.error);
|
||||||
|
}
|
||||||
|
// 'end' event requires no special handling beyond resetting the LED
|
||||||
|
}
|
||||||
|
|
||||||
recognition.onerror = function(event) {
|
// Set up event handlers using the combined function
|
||||||
console.error('Speech recognition error', event.error);
|
recognition.onresult = function(event) { handleSpeechEvent('result', event); };
|
||||||
led.style.backgroundColor = 'gray';
|
recognition.onerror = function(event) { handleSpeechEvent('error', event); };
|
||||||
};
|
recognition.onend = function() { handleSpeechEvent('end'); };
|
||||||
|
|
||||||
recognition.onend = function() {
|
|
||||||
led.style.backgroundColor = 'gray';
|
|
||||||
};
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue