Update SpeechSynthesis.tsx

This commit is contained in:
bsu3338 2023-09-03 21:58:07 -05:00 committed by GitHub
parent 95cf300782
commit e9882dedad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,11 @@ function useSpeechSynthesis() {
console.log('Toggle Text-To-Speech', !isSpeechEnabled);
};
const cancelSpeech = () => {
const synth = window.speechSynthesis;
synth.cancel();
};
const handleKeyDown = (event) => {
if (event.shiftKey && event.altKey && event.key === 'P') {
toggleSpeechSynthesis();
@ -31,11 +36,12 @@ function useSpeechSynthesis() {
if (!isSpeechEnabled || !textToSpeak) return;
const synth = window.speechSynthesis;
synth.cancel();
const utterance = new SpeechSynthesisUtterance(textToSpeak);
synth.speak(utterance);
}, [textToSpeak, isSpeechEnabled]);
return { synthesizeSpeech, toggleSpeechSynthesis, isSpeechEnabled };
return { synthesizeSpeech, toggleSpeechSynthesis, cancelSpeech, isSpeechEnabled };
}
export default useSpeechSynthesis;