
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
react-speech-reader
Advanced tools
A React hook for text-to-speech functionality with full playback control
A modern React application that converts text to speech using the Web Speech API. This application allows users to input text and have it read aloud with customizable voice settings.
To get started with React Speech Reader, follow these steps:
# Using npm
npm install react-speech-reader
# Using yarn
yarn add react-speech-reader
import { useSpeechReader } from 'react-speech-reader';
function MyComponent() {
const {
speak,
speaking,
voices,
setVoice,
setRate,
setPitch,
pause,
resume,
cancel
} = useSpeechReader({
rate: 1.0,
pitch: 1.0
});
return (
<div>
<button
onClick={() => speak('Hello, welcome to React Speech Reader!')}
disabled={speaking}
>
Speak
</button>
<button onClick={pause}>Pause</button>
<button onClick={resume}>Resume</button>
<button onClick={cancel}>Stop</button>
</div>
);
}
interface SpeechReaderOptions {
rate?: number; // Speech rate between 0.1 and 10
pitch?: number; // Speech pitch between 0 and 2
voice?: SpeechSynthesisVoice; // Browser's SpeechSynthesisVoice object
}
interface SpeechReaderHook {
speak: (text: string) => void;
speaking: boolean;
voices: SpeechSynthesisVoice[];
setVoice: (voice: SpeechSynthesisVoice) => void;
setRate: (rate: number) => void;
setPitch: (pitch: number) => void;
pause: () => void;
resume: () => void;
cancel: () => void;
}
useSpeechReader Hookfunction useSpeechReader(options?: SpeechReaderOptions): SpeechReaderHook;
| Option | Type | Default | Description |
|---|---|---|---|
| rate | number | 1.0 | Speech rate (0.1 to 10) |
| pitch | number | 1.0 | Speech pitch (0 to 2) |
| voice | SpeechSynthesisVoice | system default | Voice to use for speech |
| Value | Type | Description |
|---|---|---|
| speak | function | Function to start speaking text |
| speaking | boolean | Whether speech is currently in progress |
| voices | array | Available system voices |
| setVoice | function | Function to change the current voice |
| setRate | function | Function to change the speech rate |
| setPitch | function | Function to change the speech pitch |
| pause | function | Function to pause speaking |
| resume | function | Function to resume speaking |
| cancel | function | Function to cancel speaking |
import { useSpeechReader } from 'react-speech-reader';
function TextReader() {
const { speak, speaking } = useSpeechReader();
return (
<div>
<textarea
onChange={(e) => speak(e.target.value)}
placeholder="Type something to read..."
/>
</div>
);
}
import { useSpeechReader } from 'react-speech-reader';
function AdvancedReader() {
const {
speak,
speaking,
voices,
setVoice,
setRate,
setPitch,
pause,
resume,
cancel
} = useSpeechReader();
return (
<div>
{/* Voice Selection */}
<select onChange={(e) => setVoice(voices[e.target.value])}>
{voices.map((voice, index) => (
<option key={index} value={index}>
{voice.name}
</option>
))}
</select>
{/* Rate Control */}
<input
type="range"
min="0.1"
max="10"
step="0.1"
defaultValue="1"
onChange={(e) => setRate(parseFloat(e.target.value))}
/>
{/* Pitch Control */}
<input
type="range"
min="0"
max="2"
step="0.1"
defaultValue="1"
onChange={(e) => setPitch(parseFloat(e.target.value))}
/>
{/* Playback Controls */}
<div>
<button onClick={() => speak('Testing voice settings')}>
Speak
</button>
<button onClick={pause} disabled={!speaking}>
Pause
</button>
<button onClick={resume} disabled={!speaking}>
Resume
</button>
<button onClick={cancel} disabled={!speaking}>
Stop
</button>
</div>
</div>
);
}
This package uses the Web Speech API, which is supported in most modern browsers:
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is licensed under the MIT License.
If you find this project helpful, please give it a ⭐️!
For issues and feature requests, please create an issue on the GitHub repository.
FAQs
A React hook for text-to-speech functionality with full playback control
The npm package react-speech-reader receives a total of 0 weekly downloads. As such, react-speech-reader popularity was classified as not popular.
We found that react-speech-reader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.