Skip to content

Commit

Permalink
chore: minor error handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
emcelroy committed Jan 13, 2025
1 parent a3297b6 commit c7410cd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ export const ChatInputComponent = ({disabled, keyboardShortcutEnabled, shortcutK
speechRecognitionRef.current.interimResults = false;

speechRecognitionRef.current.onresult = (event: SpeechRecognitionEvent) => {
// const speechToText = Array.from(event.results).map(result => result[0].transcript).join("");
const latestResult = event.results[event.results.length - 1];
const speechToText = latestResult[0].transcript;
setInputValue(prevValue => (`${prevValue} ${speechToText}`).trim());
};

speechRecognitionRef.current.onerror = (event) => {
console.error("Speech recognition error detected:", event.error);
setDictationEnabled(false);
alertSound("stop");
};
}
}, []);
Expand All @@ -72,6 +73,10 @@ export const ChatInputComponent = ({disabled, keyboardShortcutEnabled, shortcutK
if (dictationEnabled) {
try {
speechRecognitionRef.current.start();
// automatically stop after 60 seconds
setTimeout(() => {
speechRecognitionRef.current?.stop();
}, 60000);
} catch (error) {
console.error("Error starting recognition:", error);
}
Expand Down

0 comments on commit c7410cd

Please sign in to comment.