Giter Site home page Giter Site logo

cdimascio / watson-html5-speech-recognition Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 3.0 99 KB

Speech Recognition for Browsers via Webkit, HTML5, and Watson

License: Apache License 2.0

JavaScript 99.34% HTML 0.66%
watson-speech watson speech-recognition web-speech-api watson-speech-sdk

watson-html5-speech-recognition's Introduction

watson-html5-speech-recognition

A Library to provide speech recognition capability in browsers.

Support

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

Prequisites

  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)

Install

npm install watson-html5-speech-recognition

Usage

var Speech = require('watson-html5-speech-recognition');
var speech = new Speech.SpeechToText();

speech.listen({
    onStart: function() {
        console.log('starting');
    },
    onResult: function(e) {
        console.log(e.text);
    },
    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).

Example

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 https://github.com/cdimascio/watson-html5-speech-recognition

Navigate to the example root:

cd example/server

Install dependencies:

npm install

Build the example:

npm run compile

Run the example:

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

Then,

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:

About the example

The watson-html5-speech-recognition library is exposed as a node module. It, thus can be used seamlessly with build tools like webpack, browserify, jspm, etc.

For the purpose of this example, we use Browserify to generate speech.js from main.js. Once generated, speech.js can be included in your webpage via script tag. See index.html.

If you want to further customize main.js, you must regenerate speech.js. To do so:

  • cd example/server
  • npm run compile

All example files live in example/server.

UI client files:

  • public/main.js sets up watson-html5-speech-recognition and adds an instance to the global space.
  • public/speech.js is generated from main.js by Browserify. (npm run compile)
  • public/index.html contains application to listen for user input and output it to the screen.

Server files:

  • app.js creates an express server and exposes a base route for speech to text endpoints
  • stt-token.js instantiates watson speech to text and provides an endpoint to request speech to text authorization tokens.

License

Apache 2.0

watson-html5-speech-recognition's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

watson-html5-speech-recognition's Issues

not run

felipe@felipeurrego:~/watson-html5-speech-recognition/example/server$ npm start

> [email protected] start /home/felipe/watson-html5-speech-recognition/example/server
> node app.js

module.js:327
    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/felipe/watson-html5-speech-recognition/example/server/app.js:2:17)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

npm ERR! Linux 4.2.0-27-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.4.4
npm ERR! npm  v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node app.js'.
npm ERR! This is most likely a problem with the example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs example
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls example
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/felipe/watson-html5-speech-recognition/example/server/npm-debug.log
felipe@felipeurrego:~/watson-html5-speech-recognition/example/server$ node app.js
module.js:327
    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/felipe/watson-html5-speech-recognition/example/server/app.js:2:17)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

Running without server-side code

I have followed your instructions but it doesn't seem to be working. The speech.js isn't being populated. It's empty after running 'npm run compile' It's empty.

Sorry I am newbie to all these. Any guidance will be highly appreciated.

Raspberry Pi3

this works with RPi3???

I'm trying to use it, but it seems they don't work together

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.