Skip to content

Instantly share code, notes, and snippets.

@shaikh-shahid
Created March 27, 2019 13:43
Show Gist options
  • Save shaikh-shahid/2aff9f2d73800469268f591e8903d71e to your computer and use it in GitHub Desktop.
Save shaikh-shahid/2aff9f2d73800469268f591e8903d71e to your computer and use it in GitHub Desktop.
try {
 var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
 var recognition = new SpeechRecognition();
 }
 catch(e) {
 console.error(e);
 $('.no-browser-support').show();
 $('.app').hide();
 }
// other code, please refer GitHub source
recognition.onresult = function(event) {
// event is a SpeechRecognitionEvent object.
// It holds all the lines we have captured so far. 
 // We only need the current one.
 var current = event.resultIndex;
// Get a transcript of what was said.
var transcript = event.results[current][0].transcript;
// send it to the backend
$.ajax({
 type: 'POST',
 url: '/command/',
 data: JSON.stringify({command: transcript}),
 success: function(data) { console.log(data) },
 contentType: "application/json",
 dataType: 'json'
 });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment