OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 /** | 5 /** |
6 * @fileoverview The manager of speech recognition. | 6 * @fileoverview The manager of speech recognition. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('speech', function() { | 9 cr.define('speech', function() { |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** | 12 /** |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 function SpeechRecognitionManager(delegate) { | 15 function SpeechRecognitionManager(delegate) { |
16 this.isActive = true; | 16 this.isActive = true; |
17 this.delegate_ = delegate; | 17 this.delegate_ = delegate; |
18 | 18 |
19 this.recognizer_ = new window.webkitSpeechRecognition(); | 19 this.recognizer_ = new window.webkitSpeechRecognition(); |
20 this.recognizer_.continuous = true; | 20 this.recognizer_.continuous = true; |
21 this.recognizer_.interimResults = true; | 21 this.recognizer_.interimResults = true; |
22 this.recognizer_.lang = navigator.language; | 22 this.recognizer_.lang = navigator.language; |
23 | 23 |
24 this.recognizer_.onresult = this.onRecognizerResult_.bind(this); | 24 this.recognizer_.onresult = this.onRecognizerResult_.bind(this); |
25 if (this.delegate_) { | 25 if (this.delegate_) { |
26 this.recognizer_.onstart = | 26 this.recognizer_.onstart = |
27 this.delegate_.onSpeechRecognitionStarted.bind(this.delegate_); | 27 this.delegate_.onSpeechRecognitionStarted.bind(this.delegate_); |
28 this.recognizer_.onend = | 28 this.recognizer_.onend = |
29 this.delegate_.onSpeechRecognitionEnded.bind(this.delegate_); | 29 this.delegate_.onSpeechRecognitionEnded.bind(this.delegate_); |
| 30 this.recognizer_.onspeechstart = |
| 31 this.delegate_.onSpeechStarted.bind(this.delegate_); |
| 32 this.recognizer_.onspeechend = |
| 33 this.delegate_.onSpeechEnded.bind(this.delegate_); |
30 this.recognizer_.onerror = this.onRecognizerError_.bind(this); | 34 this.recognizer_.onerror = this.onRecognizerError_.bind(this); |
31 } | 35 } |
32 } | 36 } |
33 | 37 |
34 /** | 38 /** |
35 * Called when new speech recognition results arrive. | 39 * Called when new speech recognition results arrive. |
36 * | 40 * |
37 * @param {Event} speechEvent The event to contain the recognition results. | 41 * @param {Event} speechEvent The event to contain the recognition results. |
38 * @private | 42 * @private |
39 */ | 43 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 * Stops the ongoing speech recognition. | 82 * Stops the ongoing speech recognition. |
79 */ | 83 */ |
80 SpeechRecognitionManager.prototype.stop = function() { | 84 SpeechRecognitionManager.prototype.stop = function() { |
81 this.recognizer_.abort(); | 85 this.recognizer_.abort(); |
82 }; | 86 }; |
83 | 87 |
84 return { | 88 return { |
85 SpeechRecognitionManager: SpeechRecognitionManager | 89 SpeechRecognitionManager: SpeechRecognitionManager |
86 }; | 90 }; |
87 }); | 91 }); |
OLD | NEW |