Update SpeechRecognition.tsx

This commit is contained in:
bsu3338 2023-09-03 22:49:08 -05:00 committed by GitHub
parent 5b80ddfba7
commit 6686126dc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import hotkeys from 'hotkeys-js';
const useSpeechRecognition = (ask) => { const useSpeechRecognition = (ask) => {
const [isSpeechSupported, setIsSpeechSupported] = useState(false); const [isSpeechSupported, setIsSpeechSupported] = useState(false);
@ -66,21 +67,17 @@ const useSpeechRecognition = (ask) => {
} }
}; };
const handleKeyDown = (e) => { useEffect(() => {
if (e.shiftKey && e.altKey && e.key === 'L') { hotkeys('shift+alt+l', (event, handler) => {
if (isSpeechSupported) { if (isSpeechSupported) {
toggleListening(); toggleListening();
} }
} });
};
useEffect(() => {
window.addEventListener('keydown', handleKeyDown);
return () => { return () => {
window.removeEventListener('keydown', handleKeyDown); hotkeys.unbind('shift+alt+l');
}; };
}); }, [isSpeechSupported]);
return { isSpeechSupported, isListening, text, toggleListening }; return { isSpeechSupported, isListening, text, toggleListening };
}; };