mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
Update SpeechSynthesis.tsx
This commit is contained in:
parent
95cf300782
commit
e9882dedad
1 changed files with 7 additions and 1 deletions
|
@ -13,6 +13,11 @@ function useSpeechSynthesis() {
|
||||||
console.log('Toggle Text-To-Speech', !isSpeechEnabled);
|
console.log('Toggle Text-To-Speech', !isSpeechEnabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cancelSpeech = () => {
|
||||||
|
const synth = window.speechSynthesis;
|
||||||
|
synth.cancel();
|
||||||
|
};
|
||||||
|
|
||||||
const handleKeyDown = (event) => {
|
const handleKeyDown = (event) => {
|
||||||
if (event.shiftKey && event.altKey && event.key === 'P') {
|
if (event.shiftKey && event.altKey && event.key === 'P') {
|
||||||
toggleSpeechSynthesis();
|
toggleSpeechSynthesis();
|
||||||
|
@ -31,11 +36,12 @@ function useSpeechSynthesis() {
|
||||||
if (!isSpeechEnabled || !textToSpeak) return;
|
if (!isSpeechEnabled || !textToSpeak) return;
|
||||||
|
|
||||||
const synth = window.speechSynthesis;
|
const synth = window.speechSynthesis;
|
||||||
|
synth.cancel();
|
||||||
const utterance = new SpeechSynthesisUtterance(textToSpeak);
|
const utterance = new SpeechSynthesisUtterance(textToSpeak);
|
||||||
synth.speak(utterance);
|
synth.speak(utterance);
|
||||||
}, [textToSpeak, isSpeechEnabled]);
|
}, [textToSpeak, isSpeechEnabled]);
|
||||||
|
|
||||||
return { synthesizeSpeech, toggleSpeechSynthesis, isSpeechEnabled };
|
return { synthesizeSpeech, toggleSpeechSynthesis, cancelSpeech, isSpeechEnabled };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useSpeechSynthesis;
|
export default useSpeechSynthesis;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue