npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-read-aloud

v1.0.2

Published

A React hook for reading text aloud using the Web Speech API

Readme

use-read-aloud

A lightweight React hook for reliable text-to-speech (read aloud) in the browser. Designed for long-form content like blogs and articles using the Web Speech API.

This hook is designed to work around common Web Speech API issues such as:

  • Random failures when reading long text
  • Unreliable behavior when resuming after long pauses
  • Missing controls like fast-forward, rewind, etc.

Note : This works fully on the client side using the browser’s built-in text-to-speech engines. No external APIs or dependencies are required.

Installation

npm install use-read-aloud

Usage

import { useReadAloud } from "use-read-aloud";

function AudioPlayer() {
  const { isPaused, togglePlay } = useReadAloud("Text to be read");

  return (
    <>
      <button onClick={togglePlay}>{isPaused ? "Play" : "Pause"}</button>
    </>
  );
}

Demo

A live demo can be found in this blog, which uses this library under the hood.

API

useReadAloud(text, options?)

Parameters

  • text - the text to be read

  • options - additional options to change the rate and pitch of the speech

type Options = {
  rate?: number; // default: 1
  pitch?: number; // default: 1
};

Returns

{
  isPaused: boolean;
  play: () => void;
  pause: () => void;
  replay: () => void;
  seekBackward: () => void;
  fastForward: () => void;
  togglePlay: () => void;
}

Examples

  1. Fast forward / seek backward
import { useReadAloud } from "use-read-aloud";

function AudioPlayer() {
  const { isPaused, togglePlay, fastForward, seekBackward } =
    useReadAloud("Text to be read");

  return (
    <>
      <button onClick={seekBackward}>Rewind</button>
      <button onClick={togglePlay}>{isPaused ? "Play" : "Pause"}</button>
      <button onClick={fastForward}>FastForward</button>
    </>
  );
}
  1. Speed up / slow down
import { useReadAloud } from "use-read-aloud";
import { useState } from "react";

function AudioPlayer() {
  const [playBackSpeed, setPlayBackSpeed] = useState<number>(1);

  const { isPaused, togglePlay } = useReadAloud("Text to be read", {
    rate: playBackSpeed,
  });

  return (
    <>
      <button onClick={togglePlay}>{isPaused ? "Play" : "Pause"}</button>
      <span>
        <button onClick={() => setPlayBackSpeed(playBackSpeed - 0.25)}>
          Minus
        </button>
        {`${playBackSpeed}x`}
        <button onClick={() => setPlayBackSpeed(playBackSpeed + 0.25)}>
          Plus
        </button>
      </span>
    </>
  );
}
  1. Replay from the start
import { useReadAloud } from "use-read-aloud";

function AudioPlayer() {
  const { isPaused, togglePlay, replay } = useReadAloud("Text to be read");

  return (
    <>
      <button onClick={togglePlay}>{isPaused ? "Play" : "Pause"}</button>
      <button onClick={replay}>Replay</button>
    </>
  );
}

Behavior

  • Long text is automatically split into smaller chunks of sentences for reliability.
  • A workaround is used as a replacement for the inconsistent speechSynthesis.resume() function. (This may restart the current sentence, which is generally acceptable and far more reliable.)

Peer dependency

  • react >= 18

Browser support

This hook uses the browser built-in Web Speech API, which is supported by most modern browsers. But, the voice quality varies by browser.

Supported:

  • Chrome

  • Edge

  • Safari

Not supported:

  • Firefox (does not support the Web Speech API)

Changelog

See CHANGELOG.md

License

MIT