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-speech-recognition2

v1.0.1

Published

A React component that converts speech from the microphone to text, with some exposed web-speech API functionality, and pause detection.

Downloads

1

Readme

react-speech-recognition

A React component that converts speech from the microphone to text.

npm version npm downloads license

How it works

SpeechRecognition is a higher order component that wraps one of your React components. In doing so, it injects some additional properties into the component that allow it to access a transcript of speech picked up from the user's microphone.

Under the hood, it uses Web Speech API. Currently, this component will only work in Chrome. It fails gracefully on other browsers.

It is recommended that you use Webpack to bundle this module with your web code.

Installation

To install:

npm install --save react-speech-recognition

To import in your React code:

import SpeechRecognition from 'react-speech-recognition'

Example usage

As only one component can be wrapped by SpeechRecognition, it is recommended that you add it to one of your root React components such as App. The transcription can then be passed down to child components.

import React, { PropTypes, Component } from 'react'
import SpeechRecognition from 'react-speech-recognition'

const propTypes = {
  // Props injected by SpeechRecognition
  transcript: PropTypes.string,
  resetTranscript: PropTypes.func,
  browserSupportsSpeechRecognition: PropTypes.bool
}

class Dictaphone extends Component {
  render() {
    const { transcript, resetTranscript, browserSupportsSpeechRecognition } = this.props

    if (!browserSupportsSpeechRecognition) {
      return null
    }

    return (
      <div>
        <button onClick={resetTranscript}>Reset</button>
        <span>{transcript}</span>
      </div>
    )
  }
}

Dictaphone.propTypes = propTypes

export default SpeechRecognition(Dictaphone)

If you are writing ES7 code, you can add the @SpeechRecognition decorator to your component's class. To use the decorator syntax, add the decorator plugin to Babel.

Global options

You can configure the default initial state of the Speech Recognition API. To change these defaults, you need to pass an options object into the wrapper like so:

const options = {
  autoStart: false
}

export default SpeechRecognition(options)(YourComponent)

or in ES7:

@SpeechRecognition(options)

autoStart [bool]

By default, the Speech Recognition API is listening to speech from the microphone. To have the API turned off by default, set this to false.

Props added to your component

transcript [string]

Transcription of all speech that has been spoken into the microphone. Is equivalent to the final transcript followed by the interim transcript, separated by a space.

resetTranscript [function]

Sets the transcription to an empty string.

startListening [function]

Causes the Web Speech API to start listening to speech from the microphone.

stopListening [function]

Causes the Web Speech API to stop listening to speech from the microphone, but will finish processing any remaining speech.

abortListening [function]

Causes the Web Speech API to stop listening to speech from the microphone, and also stop processing the current speech.

browserSupportsSpeechRecognition [bool]

If false, the browser does not support the Speech Recognition API.

listening [bool]

If true, the Web Speech API is listening to speech from the microphone.

interimTranscript [string]

Transcription of speech for which transcription hasn't finished yet.

For the current words being spoken, the interim transcript reflects each successive guess made by the transcription algorithm. When the browser’s confidence in its guess is maximized, it is added to the final transcript.

The difference between interim and final transcripts can be illustrated by an example over four iterations of the transcription algorithm:

| Final transcript | Interim transcript | |-------------------|--------------------| | 'Hello, I am' | 'jam' | | 'Hello, I am' | 'jams' | | 'Hello, I am' | 'James' | | 'Hello, I am James' | '' |

finalTranscript [string]

Transcription of speech for which transcription has finished.

recognition [Object]

The underlying object used by Web Speech API. It can be used to change the transcription language, which is the browser language if not specified. For example, to set the transcription language to Chinese:

recognition.lang = 'zh-CN'

License

MIT