| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function VoiceInput(keyboard) { | 5 function VoiceInput(keyboard) { |
| 6 this.finaResult_ = null; | 6 this.finaResult_ = null; |
| 7 this.recognizing_ = false; | 7 this.recognizing_ = false; |
| 8 this.keyboard_ = keyboard; | 8 this.keyboard_ = keyboard; |
| 9 this.recognition_ = new webkitSpeechRecognition(); | 9 this.recognition_ = new webkitSpeechRecognition(); |
| 10 this.recognition_.onstart = this.onStartHandler.bind(this); | 10 this.recognition_.onstart = this.onStartHandler.bind(this); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 * Speech recognizer returns a result. | 39 * Speech recognizer returns a result. |
| 40 * @param{Event} e The SpeechRecognition event that is raised each time | 40 * @param{Event} e The SpeechRecognition event that is raised each time |
| 41 * there | 41 * there |
| 42 * are any changes to interim or final results. | 42 * are any changes to interim or final results. |
| 43 */ | 43 */ |
| 44 onResultHandler: function(e) { | 44 onResultHandler: function(e) { |
| 45 for (var i = e.resultIndex; i < e.results.length; i++) { | 45 for (var i = e.resultIndex; i < e.results.length; i++) { |
| 46 if (e.results[i].isFinal) | 46 if (e.results[i].isFinal) |
| 47 this.finalResult_ = e.results[i][0].transcript; | 47 this.finalResult_ = e.results[i][0].transcript; |
| 48 } | 48 } |
| 49 for (var i = 0; i < this.finalResult_.length; i++) { | 49 insertText(this.finalResult_); |
| 50 sendKey(this.finalResult_.charAt(i)); | |
| 51 } | |
| 52 }, | 50 }, |
| 53 | 51 |
| 54 /** | 52 /** |
| 55 * Speech recognizer returns an error. | 53 * Speech recognizer returns an error. |
| 56 * @param{Event} e The SpeechRecognitionError event that is raised each time | 54 * @param{Event} e The SpeechRecognitionError event that is raised each time |
| 57 * there is an error. | 55 * there is an error. |
| 58 */ | 56 */ |
| 59 onErrorHandler: function(e) { | 57 onErrorHandler: function(e) { |
| 60 console.error('error code = ' + e.error); | 58 console.error('error code = ' + e.error); |
| 61 }, | 59 }, |
| 62 | 60 |
| 63 /** | 61 /** |
| 64 * Speech recognition ended. Reset mic key's icon. | 62 * Speech recognition ended. Reset mic key's icon. |
| 65 */ | 63 */ |
| 66 onEndHandler: function() { | 64 onEndHandler: function() { |
| 67 if (this.keyboard_.classList.contains('audio')) | 65 if (this.keyboard_.classList.contains('audio')) |
| 68 this.keyboard_.classList.remove('audio'); | 66 this.keyboard_.classList.remove('audio'); |
| 69 this.recognizing_ = false; | 67 this.recognizing_ = false; |
| 70 } | 68 } |
| 71 }; | 69 }; |
| OLD | NEW |