Created
March 27, 2019 13:43
-
-
Save shaikh-shahid/2aff9f2d73800469268f591e8903d71e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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