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

@colleague/speech-recognition-aws-polyfill

v0.3.1

Published

Polyfill for the SpeechRecognition browser API using AWS Transcribe

Downloads

6

Readme

speech-recognition-aws-polyfill

package size vulnerabilities

A polyfill for the experimental browser Speech Recognition API which falls back to AWS Transcribe.

Features

Note: this is not a polyfill for MediaDevices.getUserMedia() - check the support table in the link above.

Who is it for?

This Library is a good fit if you are already using AWS services (or you would just prefer to use AWS).

A polyfill also exists at: /antelow/speech-polyfill, which uses Azure Cognitive Services as a fallback. However, it seems to have gone stale with no updates for ~2 years.

Prerequisites

  • An AWS account
  • A Cognito identity pool (unauthenticated or authenticated) with the TranscribeStreaming permission.

AWS Setup Guide

  1. In the AWS console, visit the Cognito section and click Manage Identity Pools.
  2. Click Create new identity pool and give it a name.
  3. To allow anyone who visits your app to use speech recognition (e.g. for public-facing web apps) check Enable access to unauthenticated identities
  4. If you want to configure authentication instead, do so now.
  5. Click Create Pool
  6. Choose or create a role for your users. If you are just using authenticated sessions, you are only interested in the second section. If you aren't sure what to do here, the default role is fine.
  7. Make sure your role has the TranscribeStreaming policy attached. To attach this to your role search for IAM -> Roles, find your role, click "Attach policies" and search for the TranscribeStreaming role.
  8. Go back to Cognito and find your identity pool. Click Edit identity pool in the top right and make a note of your Identity pool ID

Usage

Install with npm i --save speech-recognition-aws-polyfill

Import into your application:

import SpeechRecognitionPolyfill from 'speech-recognition-aws-polyfill'

Or use from the unpkg CDN:

<script src="https://unpkg.com/speech-recognition-aws-polyfill"></script>

Create a new instance of the polyfill:

const recognition = new SpeechRecognitionPolyfill({
  IdentityPoolId: 'eu-west-1:11111111-1111-1111-1111-1111111111', // your Identity Pool ID
  region: 'eu-west-1' // your AWS region
})

Alternatively, use the create method.

const SpeechRecognition = SpeechRecognititionPolyfill.create({
  IdentityPoolId: 'eu-west-1:11111111-1111-1111-1111-1111111111', // your Identity Pool ID
  region: "eu-west-1"
});

const recognition = new SpeechRecognition()

You can then interact with recognition the same as you would with an instance of window.SpeechRecognition

The recognizer will stop capturing if it doesn't detect speech for a period. You can also stop manually with the stop() method.

Support Table

Properties

| Property | Supported | |-------------------|-----------| | lang | Yes | | grammars | No | | continuous | Yes | | interimResults | No | | maxAlternatives | No | | serviceURI | No |

Methods

| Method | Supported | |-------------------|-----------| | abort | Yes | | start | Yes | | stop | Yes |

Events

| Events | Supported | |---------------|-----------| | audiostart | Yes | | audioend | Yes | | start | Yes | | end | Yes | | error | Yes | | nomatch | Yes | | result | Yes | | soundstart | Partial | | soundend | Partial | | speechstart | Partial | | speechend | Partial |

Full Example

import SpeechRecognitionPolyfill from 'speech-recognition-aws-polyfill'

const recognition = new SpeechRecognitionPolyfill({
  IdentityPoolId: 'eu-west-1:11111111-1111-1111-1111-1111111111', // your Identity Pool ID
  region: 'eu-west-1' // your AWS region
})
recognition.lang = 'en-US'; // add this to the config above instead if you want

document.body.onclick = function() {
  recognition.start();
  console.log('Listening');
}

recognition.onresult = function(event) {
  const { transcript } = event.results[0][0]
  console.log('Heard: ', transcript)
}

recognition.onerror = console.error

Roadmap

  • Further increase parity between the two implementations by better supporting additional options and events.
  • Build a companion polyfill for speech synthesis (TTS) using AWS Polly
  • Provide a way to output the transcription as an RxJS observable

Contributing and Bugs

Questions, comments and contributions are very welcome. Just raise an Issue/PR (or, check out the fancy new Github Discussions feature)

License

MIT