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

Text to Speech

Voice Synthesizer

Uses the Web Speech API to turn text into spoken audio.

🤖
0 voices available on your device

API Reference

function useSpeech(text: string, options?: SpeechOptions)

Returns

  • state: Object with isPlaying, 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>
  )
}