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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-web-voice

v1.0.0

Published

web speech and recognition as react hook

Downloads

2

Readme

React Web Voice

Overview

react-web-voice is a library created to ease the integration of Web Speech Api (including speech synthesis and speech recognition) to your React web application.

Install

npm install react-web-voice

Web Speech Api Support

At the moment, not all browsers support Web Speech Api. The library has been developed and tested on Google Chrome, which is the only browser fully support Web Speech Api at the moment.

In the future, as other browsers adopt this feature, the library will be updated accordingly to support them.

More information on this topic can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API

React Version

The library provide two separated react hooks, namely useSpeech and useRecognition to support voice speaking and voice recognizing respectively.

As React hook is currently an alpha feature, using of the next version of react is required.

useSpeech

Usage

useSpeech can be used in your functional component to access to the speaking functions.

The hook return a list of messages that has already been spoken and a speak function that allow you to order the browser to speak.

const SpeechComponent = () => {
  const { messages, speak } = useSpeech();

  const speakButtonHandler = async () => {
    const utterance = await speak({
      text: 'Hello',
      volume: 0.5,
      rate: 1,
      pitch: 1
    });
  };

  return <button onClick={speakButtonHandler}>Click to speak</button>;
};
Speak function

As shown in the example above the speak function accept a message object which can be used to define the content of the message, the volume, rate and pitch and a callback function after the browser finish speaking.

Configure

By default, useSpeech use the Google Us English, you can require it to use other voice by passing in a config object:

// To get the full list of voices available: window.speechSynthesis.getVoices()
const { messages, speak } = useSpeech({ voice: 'Karen' });

useRecognition

Usage

useRecognition can be used in your functional component to access to the voice recognition functions.

const RecognitionComponent = () => {
  const { transcripts, listen } = useRecognition();

  const listenButtonHandler = async () => {
    const transcript = await listen();
  };

  return <button onClick={listenButtonHandler}>Start speaking</button>;
};
Listen function

As shown in the example above the listen function accept a callback function as its parameter, the callback function will be triggered with the message that the browser detects and recognizes.

Typescript

This project is written in typescript and fully support it.

Demo

An example of how to use these two hooks can found inside the demo folder.

Version 1.0 Breaking Changes

With version 1.0, we decided to get rid of the callback function on both speak and listen function but replacing them with a promise.