public/v/api.js
// ask a question and get an answer
ask a question and get an answer
ask a question and get an answer
function ask(text, callback) {
    speak(text, function () {
        console.log(text, 'Aguardando resosta...')
        $('#output').html('&nbsp;&nbsp;&nbsp;' + text)
        var recognition = new webkitSpeechRecognition();
        recognition.continuous = false;
        recognition.interimResults = false;
        recognition.onend = function (e) {
            console.log('ERROR', e)
            if (callback) {
                recognition.stop()
                clearOutput()
                callback('não entendo');
            }
        };
        recognition.onresult = function (e) {
            recognition.onend = null;
            if (callback) {
                var out = e.results[0][0].transcript.toLowerCase()
                console.log('OUT', out)
                recognition.stop()
                clearOutput()
                callback(null, out)
            }
        }
        $('#btn-start').addClass('btn-danger')
        recognition.start()
    });
}
function ask ( text , callback ) { speak ( text , function ( ) { console . log ( text , 'Aguardando resosta...' ) $ ( '#output' ) . html ( '&nbsp;&nbsp;&nbsp;' + text ) var recognition = new webkitSpeechRecognition ( ) ; recognition . continuous = false ; recognition . interimResults = false ; recognition . onend = function ( e ) { console . log ( 'ERROR' , e ) if ( callback ) { recognition . stop ( ) clearOutput ( ) callback ( 'não entendo') ; } } ; recognition . onresult = function ( e ) { recognition . onend = null ; if ( callback ) { var out = e . results [ 0 ] [ 0 ] . transcript . toLowerCase ( ) console . log ( 'OUT' , out ) recognition . stop ( ) clearOutput ( ) callback ( null , out ) } } $ ( '#btn-start' ) . addClass ( 'btn-danger' ) recognition . start ( ) } ) ; }
ask a question and get an answer
ask a question and get an answer
// ask question // get answer // cancel onend handler // callback(null, { //     out: out, //     confidence: e.results[0][0].confidence // }); // start listening