useSpeech
About
Speech synthesis hook for React that provides an easy-to-use interface for the Web Speech API. This hook allows you to convert text to speech with customizable voice settings and playback controls.
Examples
Basic example
Advanced settings example
Voice selection and callbacks example
Arguments
Argument | Type | Description |
---|---|---|
options | Object | Configuration options |
Options
Option | Type | Description | Default value |
---|---|---|---|
text | string | The text to be spoken | required |
language | string | Language code (e.g., "en-US", "es-ES", "fr-FR") | "en-US" |
voiceURI | string | Specific voice URI to use for speech | undefined |
onEnd | function | Callback function called when speech ends | undefined |
volume | number | Volume level (0 to 1) | 1 |
pitch | number | Pitch level (0 to 2) | 1 |
rate | number | Speech rate (0.1 to 10) | 1 |
Return
Return value | Type | Description |
---|---|---|
controls | Object | Object containing {start, pause, resume, stop, isPlaying} speech control functions and state |
Controls Object
Property | Type | Description |
---|---|---|
start | function | Start speaking the text |
pause | function | Pause the current speech |
resume | function | Resume paused speech |
stop | function | Stop speaking and reset |
isPlaying | boolean | Current playing state of the speech synthesis |