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

sepia-speechrecognition-polyfill

v1.0.1

Published

A polyfill for SpeechRecognition utilizing a SEPIA STT server.

Downloads

110

Readme

SEPIA SpeechRecognition Polyfill

An implementation of the SpeechRecognition portion of the Web Speech API built to function with a SEPIA STT server. This polyfill allows for developers to have consistent cross-platform support for speech recognition, including on platforms that do not have access to the Web Speech API natively.

This polyfill attempts to conform to the existing specification draft as close as possible. Any deviations will be noted below.

Setup

Installation

For use with Node or NPM:

npm i sepia-speechrecognition-polyfill

You can also load it from a CDN link:

https://cdn.jsdelivr.net/npm/[email protected]
https://unpkg.com/[email protected]

Building Locally

git clone https://github.com/msub2/sepia-speechrecognition-polyfill
cd sepia-speechrecognition-polyfill
npm i
npm run build

Usage

This polyfill requires you to connect to a SEPIA STT server. For more detailed instructions on how to set up a SEPIA STT server, you can refer to the setup instructions on the main repo here.

API

The polyfill exports a function, sepiaSpeechRecognitionInit(), and a class, SepiaSpeechRecognitionConfig.

sepiaSpeechRecognitionInit takes in a SepiaSpeechRecognitionConfig as a parameter and returns the polyfilled SpeechRecognition class.

SepiaSpeechRecognitionConfig contains properties for configuring your connection to the SEPIA STT server, which are as follows:

|Property|Description|Default Value| |-|-|-| |serverUrl|The URL for the SEPIA STT server.|"http://localhost:20741"| |clientId|The client ID to authenticate as with the SEPIA STT server.|"any"| |accessToken|The access token used to authenticate with the SEPIA STT server. On a default server installation, which is set to use a common access token, this is set to test1234. If the server is set to use individual tokens instead, this should be set to the corresponding token for the clientId.|"test1234"| |task|Allows for selecting a task-specific model without knowing its exact name.|""| |model|The name of the ASR model to use on the server. This does not need to be set if language is already set.|""| |optimizeFinalResult|If set to true, will optimize final results by converting numbers and ordinals expressed as words into integers (i.e. one -> 1, third -> 3rd, etc).|true| |engineOptions|Allows you to set options for features that may only be available in certain engines used by the server. An example would be Vosk's speaker detection, which is not available in Coqui.|{}|

Example

The following is an example of how to utilize the polyfill to support speech recognition across any browser:

import { sepiaSpeechRecognitionInit, SepiaSpeechRecognitionConfig } from './sepia-speechrecognition-polyfill.min.js';

const config = new SepiaSpeechRecognitionConfig();
// Set configuration options specific to your SEPIA STT server

const SpeechRecognition = window.webkitSpeechRecognition || sepiaSpeechRecognitionInit(config);
const speechTest = new SpeechRecognition();
speechTest.onerror = (e) => console.log(e.error, e.message);
speechTest.onresult = (e) => console.log(`${e.results[0][0].transcript} ${e.results[0].isFinal}`);
speechTest.interimResults = true;
speechTest.continuous = true;

const micButton = document.getElementById("micButton");
let toggled = false;
micButton.addEventListener('pointerup', () => {
  if (!toggled) speechTest.start()
  else speechTest.stop();
  toggled = !toggled;
});

Unimplemented Features

  • The error codes aborted, audio-capture, and bad-grammar are not currently used by the polyfill.
  • Grammars are not currently implemented. See this issue for a more in-depth discussion about implementing grammars.

Behavior Differences

  • From my testing, this polyfill actually behaves closer to spec than Chromium's implementation in regards to how continuous works.
    • On Chrome, once the first final transcript is received, recognition seems to stop, and it only returns that last transcript no matter how much you say after that. The polyfill continuously returns finalized transcripts after a set period of no speech from the user.
  • The polyfill will attempt to infer the lang property based on the document language or navigator.language. Chromium does not.
  • Chromium censors curse words/swears. The polyfill does not :)

Acknowledgements

Very special thanks goes out to Florian Quirin, maintainer of SEPIA, for creating so much of the code that this polyfill relies on.