useSpeech
A hook for Text-to-Speech (TTS) synthesis.
Overview
useSpeech uses the Web Speech API to synthesize text into speech. It allows you to control voice, rate, pitch, and volume.
Demo
API Reference
function useSpeech(text: string, options?: SpeechOptions)Returns
state: Object withisPlaying,lang,voice,rate,pitch,volume.speak(): Starts speaking.cancel(): Stops speaking.voices: Array of available voices on the device.
Usage Example
import { useSpeech } from 'react-hooks-ts'
function Robot() {
const { speak, state } = useSpeech("Hello human!")
return (
<button onClick={speak} disabled={state.isPlaying}>
Say Hello
</button>
)
}