
/* Methods:
	$name_recognition.abort()
	$name_recognition.start()
	$name_recognition.stop()
----------------------------*/

/* Properties:
	$name_recognition.grammars
	Example:
	var grammar = '#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;'
		var $name_recognition = new SpeechRecognition();
		var speechRecognitionList = new SpeechGrammarList();
		speechRecognitionList.addFromString(grammar, 1);
		$name_recognition.grammars = speechRecognitionList;
	
	$name_recognition.lang ($name_recognition.lang = 'en-US';)
	$name_recognition.continuous (default: false)
	$name_recognition.interimResults (default: false)
	$name_recognition.maxAlternatives (default: 1)
	$name_recognition.serviceURI
----------------------------*/

window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;

if ('SpeechRecognition' in window) {
  console.log('speech recognition API supported');
} else {
  console.log('speech recognition API not supported');
}

const $name_recognition = new window.SpeechRecognition();

$name_recognition.onaudiostart = function() {
  console.log('Audio capturing started');
}

$name_recognition.onend = function() {
  console.log('Speech recognition service disconnected');
}

$name_recognition.onend = function() {
  console.log('Speech ended');
}

$name_recognition.onerror = function(event) {
  console.log('Speech recognition error detected: ' + event.error);
}

$name_recognition.onnomatch = function() {
  console.log('Speech not recognised');
}

$name_recognition.onresult = (event) => {
  console.log(event.results[0][0].transcript);
}

$name_recognition.onsoundstart = function() {
  console.log('Some sound is being received');
}

$name_recognition.onsoundend = function() {
  console.log('Sound has stopped being received');
}

$name_recognition.onspeechstart = function() {
  console.log('Speech has been detected');
}

$name_recognition.onspeechend = function() {
  console.log('Speech has stopped being detected');
}

$name_recognition.onstart = function() {
  console.log('Speech recognition service has started');
}



