Download client/src/hooks/Input/useTextToSpeechBrowser.ts from Zhitomir/chat: direct link, hf CLI and curl.
- Browser
- Download file 658 Bytes
-
https://huggingface.co/spaces/Zhitomir/chat/resolve/main/client/src/hooks/Input/useTextToSpeechBrowser.ts
- Command line
-
hf download hf://spaces/Zhitomir/chat/client/src/hooks/Input/useTextToSpeechBrowser.ts
-
curl -L -o useTextToSpeechBrowser.ts https://huggingface.co/spaces/Zhitomir/chat/resolve/main/client/src/hooks/Input/useTextToSpeechBrowser.ts
658 Bytes
| 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; | |