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-speak

v2.0.1

Published

Higher-order React component that wraps the web SpeechRecognition API and converts speech from microphone to text.

Downloads

1

Readme

react-speak

Simple, extensible React HOC for interop with the Web SpeechRecognition API.

Dependencies:

Install

Do:

$ npm install react-speak

or:

$ yarn add react-speak

Simple Usage

Using react-speak is pretty simple because it's designed to do one thing well: allow your React/Redux components to work with your browser's native Web SpeechRecognition API and give you access to a user's microphone.

Under the hood, withSpeech is a function that takes a component and returns a wrapped component with the following PropTypes:

WithSpeech.propTypes = {
  startListening: PropTypes.func.isRequired,
  stopListening: PropTypes.func.isRequired,
  addToRegister: PropTypes.func,
}

The package was written to be used with Redux, so all three props were designed to be action creators that return action objects (see the Redux section below).

Example Setup

Here's a simple setup using Redux:

import withSpeech from 'react-speak'
import React from 'react'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { startListening, stopListening, addToRegister, clearRegister } from '../actions/speech'

// Whatever state you care about:
const mapStateToProps = state => ({ 
  isListening: state.isListening,
  register: state.register
})

const mapDispatchToProps = {
  startListening,
  stopListening,
  addToRegister,
  clearRegister
}

const YourComponentWithSpeech = props => (
  <div className="ComponentWithSpeech">
    {props.isListening
      ? null 
      : (
        <button onClick={() => onSave(props.register)}>
		  Start speaking
        </button>
      )
    }
    <div className="transcript">
      {props.register.map(transcript => <div>{transcript}</div>)}
    </div>
  </div>
)

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  withSpeech,
)(YourComponentWithSpeech)

Redux:

withSpeech returns a component with the following props:

  • startListening (function, required)
  • stopListening (function, required)
  • addToRegister (function)

All three are action creators that return action objects.

startListening and stopListening are similar in that they don't receive any particular payload from the withSpeech component; your action creator could be as simple as:

const startListening = () => ({ type: INIT_LISTEN })

addToRegister on the other hand receives a transcript or "register", which is just an array of strings from your user's microphone. You can pass this as a payload to your reducers and do whatever you want with next.

An example action creator:

const sendToAlexa = transcript => ({
  type: TRANSCRIPT_SENT,
  payload: transcript
})

FAQ:

  • Q: Do I have to use Redux?

  • A: Currently this only officially supports a Redux or Flux-type model where you have reducers that listen for the actions that withSpeech returns, and manages the logic for how this component actually mutates state.

  • Q: How can I contribute?

  • A: Contributions are totally welcome! See the section on contributing below.

Contributing

PRs that abstract this component's functionality to React in general are absolutely welcome! Also, drop me a line if you're interested in helping me work with the SpeechSynthesis interface, as currently withSpeech only implements the SpeechRecognition protocol.