mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
27 lines
658 B
TypeScript
27 lines
658 B
TypeScript
import { useState } from 'react';
|
|||
|
|||
function useTextToSpeechBrowser() {
|
|||
const [isSpeaking, setIsSpeaking] = useState(false);
|
|||
|
|||
const generateSpeechLocal = (text: string) => {
|
|||
const synth = window.speechSynthesis;
|
|||
synth.cancel();
|
|||
const utterance = new SpeechSynthesisUtterance(text);
|
|||
utterance.onend = () => {
|
|||
setIsSpeaking(false);
|
|||
};
|
|||
setIsSpeaking(true);
|
|||
synth.speak(utterance);
|
|||
};
|
|||
|
|||
const cancelSpeechLocal = () => {
|
|||
const synth = window.speechSynthesis;
|
|||
synth.cancel();
|
|||
setIsSpeaking(false);
|
|||
};
|
|||
|
|||
return { generateSpeechLocal, cancelSpeechLocal, isSpeaking };
|
|||
}
|
|||
|
|||
export default useTextToSpeechBrowser;
|