node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


Fork of Carmine DiMascio watson-html5-speech-recognition lib modified by adding to return confidence score also in result.

webkit | watson-html5-speech-recognition

A Library to provide speech recognition capability in browsers.


The library enables speech recognition support for any browser that includes support for either:

If the browser does not support either of the above, then currently you're out of luck.

watson-html5-speech-recognition use Web Speech API when present and Watson Speech To Text service for all other (supported) cases.

Currently, the following are supported:

  • Webkit speech recognition

    • Chrome (33)
    • FireFox (>=44)
  • Watson Speech to Text

    • Microsoft Edge
    • Firefox (<44)
    • Opera


  1. An instance of Watson Speech To Text Service (requires a Bluemix account)
  2. Watson Speech to Text Websocket server (provided. see Example section below)


npm install watson-html5-speech-recognition


var Speech = require('watson-html5-speech-recognition');
var speech = new Speech.SpeechToText();
    onStart: function() {
    onResult: function(e) {
    onError: function(e) {
        console.log('error', e);
    onEnd: function(e) {
        console.log('end', e);

Customized Usage

If Watson speech services are engaged, the watson-html5-speech-recognition request a token from the server then communicates via websocket.

By default, watson-html5-speech-recognition assumes the token endpoint exists at /api/speech-to-text/token. If you alter the location of that endpoint, you must supply the new location via a configuration parameter upon instantiation. Like so...

var Speech = require('watson-html5-speech-recognition');
var speech = new Speech.SpeechToText({
  watsonTokenUrl: `/path/to/my/speech-to-text/token`

NOTE: The example server uses the watson-developer-cloud npm package to configure the token endpoint (see example/server/stt-token.js).


The example contains a simple web front end, along with a backend web socket server that communicates with the Watson Speech To Text service

Setup the example

Clone the example:

git clone

Navigate to the example root:

cd example/server

Install dependencies:

npm install

Build the example:

npm compile

Run the example:

First, be sure to complete all steps in the section above, "Setup the example"


Open stt-token.js to line 10

Set '<your-username>' and '<your-username>' to match your Watson Speech To Text Service credentials.

npm start

Try it:


Apache 2.0