函数内部的函数不返回文本//从内部函数预期输出“完成”中未获取返回值

时间:2019-03-01 05:21:26

标签: javascript

     var text=""
  var flag=0;

    function startDictation() {
      var mes=""
console.log('Inside Start dictation function');

        document.getElementById('img').src='images/mp copy.jpg';
      flag=1;
      if (window.hasOwnProperty('webkitSpeechRecognition')) {
        var recognition = new webkitSpeechRecognition();
        recognition.continuous = false;
        recognition.interimResults = false;
        recognition.lang = "en-US";
        recognition.start();
        recognition.onresult = function(e) {
        document.getElementById('transcript').value
                                   = e.results[0][0].transcript;
        recognition.stop();

        var text= $('#transcript').val();
             if(text){
                  // alert(text);
                  $.map(JSONObject.Alexa, function(elem, index) {
                    //console.log(elem);
                        if (elem.que1 == text){ 
                        console.log(elem.que1+" Metched");
                  document.getElementById('img').src='images/mp.jpg';
                  // console.log('Resume button clicked');
                  // document.getElementById("loop_controler").click();
                     }
                  });
              mes="done"
              return mes;
                }

            }; 

            recognition.onerror = function(e) {
          recognition.stop();
        }
       // return mes;

      }
}
var listen =startDictation();

if(listen=='Done'){
call another function 
}

如果文本正确,请尝试调用上述函数我想要文本消息。 我只是想在调用主函数并希望检查是否满足条件时从RecognitionOnResult内部函数返回一些文本

0 个答案:

没有答案