Skip to content

Instantly share code, notes, and snippets.

@shaikh-shahid
Created March 27, 2019 13:43

Revisions

  1. shaikh-shahid created this gist Mar 27, 2019.
    27 changes: 27 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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'
     });
    };