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 offline hotword speech recognizer plugin. | 6 * @fileoverview The manager of offline hotword speech recognizer plugin. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('speech', function() { | 9 cr.define('speech', function() { |
10 'use strict'; | 10 'use strict'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 }; | 32 }; |
33 | 33 |
34 /** | 34 /** |
35 * The regexp pattern of the hotword recognition result. | 35 * The regexp pattern of the hotword recognition result. |
36 */ | 36 */ |
37 var recognitionPattern = /^(HotwordFiredEvent:|hotword)/; | 37 var recognitionPattern = /^(HotwordFiredEvent:|hotword)/; |
38 | 38 |
39 /** | 39 /** |
40 * @constructor | 40 * @constructor |
41 */ | 41 */ |
42 function PluginManager(onReady, onRecognized) { | 42 function PluginManager(prefix, onReady, onRecognized) { |
43 this.state = PluginState.UNINITIALIZED; | 43 this.state = PluginState.UNINITIALIZED; |
44 this.onReady_ = onReady; | 44 this.onReady_ = onReady; |
45 this.onRecognized_ = onRecognized; | 45 this.onRecognized_ = onRecognized; |
46 this.samplingRate_ = null; | 46 this.samplingRate_ = null; |
47 this.config_ = null; | 47 this.config_ = null; |
48 var recognizer = $('recognizer'); | 48 var recognizer = $('recognizer'); |
49 if (!recognizer) { | 49 if (!recognizer) { |
50 recognizer = document.createElement('EMBED'); | 50 recognizer = document.createElement('EMBED'); |
51 recognizer.id = 'recognizer'; | 51 recognizer.id = 'recognizer'; |
52 recognizer.type = 'application/x-nacl'; | 52 recognizer.type = 'application/x-nacl'; |
53 recognizer.src = 'chrome://app-list/greconacl.nmf'; | 53 recognizer.src = 'chrome://app-list/hotword_' + prefix + '.nmf'; |
54 recognizer.width = '1'; | 54 recognizer.width = '1'; |
55 recognizer.height = '1'; | 55 recognizer.height = '1'; |
56 document.body.appendChild(recognizer); | 56 document.body.appendChild(recognizer); |
57 } | 57 } |
58 recognizer.addEventListener('message', this.onMessage_.bind(this)); | 58 recognizer.addEventListener('message', this.onMessage_.bind(this)); |
59 recognizer.addEventListener('load', this.onLoad_.bind(this)); | 59 recognizer.addEventListener('load', this.onLoad_.bind(this)); |
60 }; | 60 }; |
61 | 61 |
62 /** | 62 /** |
63 * The event handler of the plugin status. | 63 * The event handler of the plugin status. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 PluginManager.prototype.sendAudioData = function(event) { | 146 PluginManager.prototype.sendAudioData = function(event) { |
147 if (this.state == PluginState.RECOGNIZING) | 147 if (this.state == PluginState.RECOGNIZING) |
148 $('recognizer').postMessage(event.data.buffer); | 148 $('recognizer').postMessage(event.data.buffer); |
149 }; | 149 }; |
150 | 150 |
151 return { | 151 return { |
152 PluginManager: PluginManager, | 152 PluginManager: PluginManager, |
153 PluginState: PluginState, | 153 PluginState: PluginState, |
154 }; | 154 }; |
155 }); | 155 }); |
OLD | NEW |