function SpeechPlus(options) { this._init(options); } SpeechPlus.prototype = { _init: function (options) { var that = this; this.recogniz = document.getElementById(options.recogniz); debugger this.partial = document.getElementById(options.partial); this.volume = document.getElementById(options.volume); this.done = document.getElementById(options.done); this.done.addEventListener('touchstart', function () { plus.speech.startRecognize({ engine: 'baidu', lang: 'zh-cn', 'userInterface': false, 'continue': true }); that.recogniz.style.visibility = 'visible'; }, false); this.done.addEventListener('touchend', function () { plus.speech.stopRecognize(); that.recogniz.style.visibility = 'hidden'; }, false); this.text = ''; }, initSpeech: function (callback) { var that = this; plus.speech.addEventListener('start', function () { console.log('Event: start'); that.text = null; that.partial.innerText = ''; }, false); plus.speech.addEventListener('volumeChange', function (e) { that.volume.style.width = 100 * e.volume + 'px'; }, false); plus.speech.addEventListener('recognizing', function (e) { console.log('Event: recognizing'); that.partial.innerText = e.partialResult; }, false); plus.speech.addEventListener('recognition', function (e) { console.log('Event: recognition'); that.text ? (that.text += '\n') : that.text = ''; that.text += e.result; that.partial.innerText = e.result; callback(that.text); }, false); plus.speech.addEventListener('end', function () { console.log('Event: end'); if (!that.text || that.text == '') { plus.nativeUI.toast('没有识别到内容'); } }, false); }, doStart: function (recogniz) { plus.speech.startRecognize({ engine: 'baidu', lang: 'zh-cn', 'userInterface': false, 'continue': true }); recogniz.style.visibility = 'visible'; }, doEnd: function () { plus.speech.stopRecognize(); this.recogniz.style.visibility = 'hidden'; }, startRecognizeSilent: function () { var options = { userInterface: false }; plus.speech.startRecognize(options, function (s) { console.log('success: ' + s); }, function (e) { console.log('error: ' + JSON.stringify(e)); }); } }