Skip to content

Latest commit

 

History

History
81 lines (50 loc) · 1.78 KB

README.md

File metadata and controls

81 lines (50 loc) · 1.78 KB

speechJS

Simple webkitSpeechRecognition wrapper class. (Google Chrome ONLY!)

Usage:

Create new instance:

var sr = new SpeechRecognition();

Add event handler:

sr.on([Name of event],  function() {});

Set options

sr.set([option_name], [value]);

or

sr.set({
	[option_name] : [value],
	[option_name] : [value]
});

Start:

sr.start();

Stop:

sr.stop();

Options:

Events:

  • "starting" : Fired when user starting speech recognition.
  • "started" : Fired when speech recognition is started.
  • "stopping" : Fired when user stopping speech recognition.
  • "stopped" : Fired when speech recogniton is stopped.
  • "optionschanged" : Fired when user change speech recognition's settings.
  • "error" : Fired when an error occurs.
  • "result" : Fired when speech recognition got results.

Handle Error & Result events

Example:

sr.on("error", function(e) {
	console.log("[SpeechRecognition]", "Error:", e);
});

sr.on("result", function(evt) {
	console.log("[SpeechRecognition]", "Result:", evt);
	
	for (var i = evt.resultIndex; i < evt.results.length; ++i) {
	  if (evt.results[i].isFinal) {
		output.value += evt.results[i][0].transcript +" | ";
	  } else {
		//evt.results[i][0].transcript; <-- Not fully recognized (alias: interim script)!
	  }
	}
	
});