zzmp / juliusjs

A speech recognition library for the web
https://zzmp.github.io/juliusjs
Other
2.58k stars 176 forks source link

JuliusJS

A speech recognition library for the web

Try the live demo.

JuliusJS is an opinionated port of Julius to JavaScript.
It actively listens to the user to transcribe what they are saying through a callback.

// bootstrap JuliusJS
var julius = new Julius();

julius.onrecognition = function(sentence) {
    console.log(sentence);
};

// say "Hello, world!"
// console logs: `> HELLO WORLD`
Features:

Quickstart

Using Express 4.0
  1. Grab the latest version with bower
    • bower install juliusjs --save
  2. Include julius.js in your html
    • <script src="https://github.com/zzmp/juliusjs/raw/master/julius.js"></script>
  3. Make the scripts available to the client through your server

    var express = require('express'),
      app     = express();
    
    app.use(express.static('path/to/dist'));
  4. In your main script, bootstrap JuliusJS and register an event listener for recognition events

    // bootstrap JuliusJS
    var julius = new Julius();
    
    // register listener
    julius.onrecognition = function(sentence, score) {
      // ...
      console.log(sentence);
    };

Configure your own recognition grammar

In order for JuliusJS to use it, your grammar must follow the Julius grammar specification. The site includes a tutorial on writing grammars.
By default, phonemes are defined in voxforge/hmmdefs, though you might find other sites more useful as reference.

  1. Write a yourGrammar.voca file with words to be recognized
    • The .voca file defines "word candidates" and their pronunciations.
  2. Write a yourGrammar.grammar file with phrases composed of those words
    • The .grammar file defines "category-level syntax, i.e. allowed connection of words by their category name."
  3. Compile the grammar using ./bin/mkdfa.pl yourGrammar
    • The .voca and .grammar must be prefixed with the same name
    • This will generate yourGrammar.dfa and yourGrammar.dict
  4. Give the new .dfa and .dict files to the Julius constructor

    // when bootstrapping JuliusJS
    var julius = new Julius('path/to/dfa', 'path/to/dict');

Advanced Use

Configuring the engine

The Julius constructor takes three arguments which can be used to tune the engine:

new Julius('path/to/dfa', 'path/to/dict', options)

Both 'path/to/dfa' and 'path/to/dict' must be set to use a custom grammar

'path/to/dfa'
'path/to/dict'
options

Examples

Voice Command

Coming soon...

Keyword Spotting (e.g., API integration)

Coming soon...

In the wild

If you use JuliusJS let me know, and I'll add your project to this list (or issue a pull request yourself).

  1. Coming soon...

Motivation

Future goals

Developers

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Build from source

You'll need emscripten, the LLVM to JS compiler, to build this from the C source. Once you have that, run ./emscript.sh. If you are missing other tools, the script will let you know.

As emscript.sh reloads and recompiles static libraries, ./reemscript.sh is available once you've already run emscript.sh. reemscript.sh will only recompile to JavaScript based on your latest changes. This can also be run with npm make.

Additionally, tests are set will be made to run using npm test.
In the meantime, a blank page with the JuliusJS library can be served using npm start.

Codemap

emscript.sh / reemscript.sh

These scripts will compile/recompile Julius C source to JavaScript, as well as copy all other necessary files, to the js folder.

emscript.sh will also compile binaries, which you can use to create recognition grammars or compile grammars to smaller binary files. These are copied to the bin folder.

src

This is where the source for Julius will go once emscript.sh is run. emscript.sh will replace certain files in src/julius4 with those in src/include in order to make src/emscripted, the files eventually compiled to JavaScript.

Files in bold were changed to replace a loop with eventing, to simulate multithreading in a Worker.

js

The home to the testing server run with npm start. Files are copied to this folder from dist with emscript.sh and reemscript.sh. If they are modified, they should be commited back to the dist folder.

dist

The home for committed copies of the compiled library, as well as the wrappers that make them work: julius.js and worker.js. dist/listener/converter.js is the file that actually pipes Web Audio to Julius (the compiled C program).


JuliusJS is a port of the "Large Vocabulary Continuous Speech Recognition Engine Julius" to JavaScript