jquery - Web speech api with default timeout in Javascript -


i'm using following demo recognize speech. it's working taking more time load or recognize speech text. not sure why is! there way set default timeout recognize function if default maximum timeout exceeded call other callback function?

<script>   // test browser support   window.speechrecognition = window.speechrecognition       ||                              window.webkitspeechrecognition ||                              null;    if (window.speechrecognition === null) {     document.getelementbyid('ws-unsupported').classlist.remove('hidden');     document.getelementbyid('button-play-ws').setattribute('disabled', 'disabled');     document.getelementbyid('button-stop-ws').setattribute('disabled', 'disabled');   } else {     var recognizer = new window.speechrecognition();     var transcription = document.getelementbyid('transcription');     var log = document.getelementbyid('log');      // recogniser doesn't stop listening if user pauses     recognizer.continuous = true;      // start recognising     recognizer.onresult = function(event) {       transcription.textcontent = '';        (var = event.resultindex; < event.results.length; i++) {         if (event.results[i].isfinal) {           transcription.textcontent = event.results[i][0].transcript + ' (confidence: ' + event.results[i][0].confidence + ')';         } else {           transcription.textcontent += event.results[i][0].transcript;         }       }     };      // listen errors     recognizer.onerror = function(event) {       log.innerhtml = 'recognition error: ' + event.message + '<br />' + log.innerhtml;     };      document.getelementbyid('button-play-ws').addeventlistener('click', function() {       // set if need interim results       recognizer.interimresults = document.queryselector('input[name="recognition-type"][value="interim"]').checked;        try {         recognizer.start();         log.innerhtml = 'recognition started' + '<br />' + log.innerhtml;       } catch(ex) {         log.innerhtml = 'recognition error: ' + ex.message + '<br />' + log.innerhtml;       }     });      document.getelementbyid('button-stop-ws').addeventlistener('click', function() {       recognizer.stop();       log.innerhtml = 'recognition stopped' + '<br />' + log.innerhtml;     });      document.getelementbyid('clear-all').addeventlistener('click', function() {       transcription.textcontent = '';       log.textcontent = '';     });   } </script> 

thanks in advance!

dont forget use onspeechend function. function detects when speech has ended, can put instructions want when speech has ended.

you want recognition ends when stop talk, so:

example:

recognition.onspeechend = function() {   recognition.stop(); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -