Skip to content

kdavis-mozilla/dictatemp3.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

dictatemp3.js

dictatemp3.js is a small Javascript library for browser-based real-time speech recognition. It uses recordermp3.js for audio capture, and a WebSocket connection to the Kaldi DNN GStreamer server for speech recognition.

Quick Start

When installed dictatemp3.js exposes the classes Dictate and Transcription. The following snippet is an example of their use

// Create Transcription to hold utterance
var transcription = new Transcription();

// Create Dictate for speech-to-text
var dictate = new Dictate({
  server: 'ws://<server ip>:8888/client/ws/speech',
  serverStatus: 'ws://<server ip>:8888/client/ws/status',
  referenceHandler: 'ws://<server ip>:8888/client/dynamic/reference',
  mp3RecorderWorkerPath: 'vendor/recordermp3.js/js/enc/mp3/mp3Worker.js',
  onReadyForSpeech: function() {
    dictate.isConnected = true;
    console.info('Ready for speech');
  },
  onEndOfSpeech: function() {
    console.info('End of speech');
  },
  onEndOfSession: function() {
    dictate.isConnected = false;
    console.info('End of session');
  },
  onServerStatus: function(json) {
    if (json.num_workers_available == 0 && !dictate.isConnected) {
      console.info('Waiting');
    }  else {
      console.info('Ready');
    }
  },
  onPartialResults: function(hypos) {
    transcription.add(hypos[0].transcript, false); // TODO: Generalize to more results
    console.info('onPartialResults: ' + transcription.toString());
  },
  onResults: function(hypos) {
    transcription.add(hypos[0].transcript, true); // TODO: Generalize to more results
    console.info('onResults: ' + transcription.toString());
    transcription = new Transcription();
  },
  onError: function(code, data) {
    dictate.cancel();
    console.warn('ERROR: ' + code + ': ' + (data || '')); 
  },
  onEvent: function(code, data) {
    console.info('EVENT: ' + code + ': ' + (data || '')); 
  }
});

// Init dictate.isConnected
dictate.isConnected = false;

// Init Dictate
dictate.init();

To see a fuller example refer to iris in particular main.js.

API

The API is modelled after Android's SpeechRecognizer. See the source code of lib/dictate.js.

Browser support

Known to work in

  • Firefox 45.0a1 on OSX desktop

See also

  • Kõnele contains an Android front-end to the Kaldi GStreamer server

About

Browser based speech recognition using the kaldi-gstreamer-server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •