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

@intentface/react-speech-recognition

v1.0.6

Published

`@intentface/react-speech-recognition` is a custom React hook that provides an easy-to-use interface for integrating speech recognition capabilities into your React applications. It leverages the native browser `SpeechRecognition` API, allowing you to cap

Downloads

98

Readme

@intentface/react-speech-recognition

@intentface/react-speech-recognition is a custom React hook that provides an easy-to-use interface for integrating speech recognition capabilities into your React applications. It leverages the native browser SpeechRecognition API, allowing you to capture and process voice inputs with customizable options.

Installation

You can install this package via npm:

npm install @intentface/react-speech-recognition

Usage

Here’s a basic example of how to use the useSpeechRecognition hook in your React project:

import React from "react";
import { useSpeechRecognition } from "@intentface/react-speech-recognition";

const SpeechComponent = () => {
  const {
    transcript,
    interimTranscript,
    isListening,
    isFinal,
    isSupported,
    start,
    stop,
    error,
  } = useSpeechRecognition({
    lang: "en-US", // Language for speech recognition (default is "en-US")
    continuous: false, // Whether to keep listening or stop after receiving input
    timeout: 5000, // Automatically stop listening after 5 seconds
    onUpdate: ({ transcript, interimTranscript, isFinal }) => {
      console.log("Update:", { transcript, interimTranscript, isFinal });
    },
    onError: ({ error }) => {
      console.error("Speech recognition error:", error);
    },
  });

  if (!isSupported) {
    return <p>Your browser does not support Speech Recognition.</p>;
  }

  return (
    <div>
      <h1>Speech Recognition Example</h1>
      <p>Transcript: {transcript}</p>
      <p>Interim Transcript: {interimTranscript}</p>
      <p>
        Status:{" "}
        {isListening ? "Listening..." : isFinal ? "Finalized" : "Stopped"}
      </p>
      {error && <p>Error: {error.message}</p>}
      <button onClick={start}>Start Listening</button>
      <button onClick={stop}>Stop Listening</button>
    </div>
  );
};

export default SpeechComponent;

API

The useSpeechRecognition hook returns an object containing the following properties:

Returned Values

  • transcript: The final processed transcript of the recognized speech.
  • interimTranscript: The current intermediate transcript while speech is being processed.
  • isListening: A boolean indicating whether the recognition is currently active.
  • isFinal: A boolean indicating whether the current session has ended and the transcript is finalized.
  • isSupported: A boolean indicating whether the browser supports speech recognition.
  • start(): A function to start speech recognition.
  • stop(): A function to stop speech recognition.
  • error: An object containing any speech recognition errors that occurred.

Options

The hook accepts an options object with the following fields:

  • lang: The language for speech recognition (default is "en-US").
  • continuous: If true, the recognition will continue until stopped manually (default: false).
  • timeout: Time in milliseconds to automatically stop recognition after no speech is detected (default: undefined). If left undefined, browsers default behaviour is respected.
  • onUpdate: A callback function triggered when there is an update in the transcript. Receives an object with { transcript, interimTranscript, isFinal }.
  • onError: A callback function triggered when an error occurs. Receives an object with { error }.

Features

  • Customizable Language: Set the language of recognition with the lang option.
  • Continuous Listening: Option to listen continuously for speech input.
  • Timeout Control: Automatically stop recognition after a set period of inactivity.
  • Error Handling: Receive error information via the onError callback.
  • Interim and Final Transcripts: Access both the interim (in-progress) and final transcripts.

Browser Compatibility

This hook uses the native SpeechRecognition API (also known as webkitSpeechRecognition in some browsers). Below is a list of supported browsers:

| Browser | Supported Versions | | ------- | ------------------ | | Chrome | Version 33+ | | Safari | Version 14+ | | Edge | Version 79+ |

Note: The SpeechRecognition API is not supported in Firefox or Internet Explorer. Please check for browser compatibility using the isSupported flag provided by the hook.

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to create a pull request or file an issue in the repository.

Please remember to add the changes you are making by running

npm run add-change

License

MIT

Dev

Doing a release

After finishing your feature normally, to automatically bump version number, update changelog and do an npm release:

  1. npm run add-change
  2. Follow the instructions
  3. Commit the changeset file(s) to your feature branch and push to Github
  4. Create a PR normally, including the changeset file(s)
  5. Eventually accept the PR called "Version Packages" created by the changeset bot

About us

For more details about who we are, visit our website: Intentface.