OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('hotword', function() { | 5 cr.define('hotword', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Class used to manage speaker training. Starts a hotwording session | 9 * Class used to manage speaker training. Starts a hotwording session |
10 * if training is on, and automatically restarts the detector when a | 10 * if training is on, and automatically restarts the detector when a |
(...skipping 10 matching lines...) Expand all Loading... |
21 */ | 21 */ |
22 this.finalizedSpeakerModelListener_ = | 22 this.finalizedSpeakerModelListener_ = |
23 this.handleFinalizeSpeakerModel_.bind(this); | 23 this.handleFinalizeSpeakerModel_.bind(this); |
24 | 24 |
25 hotword.BaseSessionManager.call(this, | 25 hotword.BaseSessionManager.call(this, |
26 stateManager, | 26 stateManager, |
27 hotword.constants.SessionSource.TRAINING); | 27 hotword.constants.SessionSource.TRAINING); |
28 } | 28 } |
29 | 29 |
30 /** | 30 /** |
31 * Handles a success event on mounting the file system event. | 31 * Handles a success event on mounting the file system event and deletes |
| 32 * the user data files. |
32 * @param {FileSystem} fs The FileSystem object. | 33 * @param {FileSystem} fs The FileSystem object. |
33 * @private | 34 * @private |
34 */ | 35 */ |
35 TrainingManager.onRequestFileSystemSuccess_ = function(fs) { | 36 TrainingManager.deleteFiles_ = function(fs) { |
36 fs.root.getFile(hotword.constants.SPEAKER_MODEL_FILE_NAME, {create: false}, | 37 fs.root.getFile(hotword.constants.SPEAKER_MODEL_FILE_NAME, {create: false}, |
37 TrainingManager.deleteFile_, TrainingManager.fileErrorHandler_); | 38 TrainingManager.deleteFile_, TrainingManager.fileErrorHandler_); |
38 | 39 |
39 for (var i = 0; i < hotword.constants.NUM_TRAINING_UTTERANCES; ++i) { | 40 for (var i = 0; i < hotword.constants.NUM_TRAINING_UTTERANCES; ++i) { |
40 fs.root.getFile(hotword.constants.UTTERANCE_FILE_PREFIX + i + | 41 fs.root.getFile(hotword.constants.UTTERANCE_FILE_PREFIX + i + |
41 hotword.constants.UTTERANCE_FILE_EXTENSION, | 42 hotword.constants.UTTERANCE_FILE_EXTENSION, |
42 {create: false}, | 43 {create: false}, |
43 TrainingManager.deleteFile_, TrainingManager.fileErrorHandler_); | 44 TrainingManager.deleteFile_, TrainingManager.fileErrorHandler_); |
44 } | 45 } |
45 }; | 46 }; |
(...skipping 20 matching lines...) Expand all Loading... |
66 /** | 67 /** |
67 * Handles a failure event on mounting the file system event. | 68 * Handles a failure event on mounting the file system event. |
68 * @param {FileError} e The FileError object. | 69 * @param {FileError} e The FileError object. |
69 * @private | 70 * @private |
70 */ | 71 */ |
71 TrainingManager.fileErrorHandler_ = function(e) { | 72 TrainingManager.fileErrorHandler_ = function(e) { |
72 hotword.debug('File error: ' + e.code); | 73 hotword.debug('File error: ' + e.code); |
73 }; | 74 }; |
74 | 75 |
75 /** | 76 /** |
| 77 * Handles a failure event on checking for the existence of the speaker model. |
| 78 * @param {FileError} e The FileError object. |
| 79 * @private |
| 80 */ |
| 81 TrainingManager.sendNoSpeakerModelResponse_ = function(e) { |
| 82 chrome.hotwordPrivate.speakerModelExistsResult(false); |
| 83 }; |
| 84 |
| 85 /** |
| 86 * Handles a success event on mounting the file system and checks for the |
| 87 * existence of the speaker model. |
| 88 * @param {FileSystem} fs The FileSystem object. |
| 89 * @private |
| 90 */ |
| 91 TrainingManager.speakerModelExists_ = function(fs) { |
| 92 fs.root.getFile(hotword.constants.SPEAKER_MODEL_FILE_NAME, {create: false}, |
| 93 TrainingManager.sendSpeakerModelExistsResponse_, |
| 94 TrainingManager.sendNoSpeakerModelResponse_); |
| 95 }; |
| 96 |
| 97 /** |
| 98 * Sends a response through the HotwordPrivateApi indicating whether |
| 99 * the speaker model exists. |
| 100 * @param {FileEntry} fileEntry The FileEntry object. |
| 101 * @private |
| 102 */ |
| 103 TrainingManager.sendSpeakerModelExistsResponse_ = function(fileEntry) { |
| 104 if (fileEntry.isFile) { |
| 105 hotword.debug('File found: ' + fileEntry.fullPath); |
| 106 if (hotword.DEBUG || window.localStorage['hotword.DEBUG']) { |
| 107 fileEntry.getMetadata(function(md) { |
| 108 hotword.debug('File size: ' + md.size); |
| 109 }); |
| 110 } |
| 111 } |
| 112 chrome.hotwordPrivate.speakerModelExistsResult(fileEntry.isFile); |
| 113 }; |
| 114 |
| 115 /** |
76 * Handles a request to delete the speaker model. | 116 * Handles a request to delete the speaker model. |
77 */ | 117 */ |
78 TrainingManager.handleDeleteSpeakerModel = function() { | 118 TrainingManager.handleDeleteSpeakerModel = function() { |
79 window.webkitRequestFileSystem(PERSISTENT, | 119 window.webkitRequestFileSystem(PERSISTENT, |
80 hotword.constants.FILE_SYSTEM_SIZE_BYTES, | 120 hotword.constants.FILE_SYSTEM_SIZE_BYTES, |
81 TrainingManager.onRequestFileSystemSuccess_, | 121 TrainingManager.deleteFiles_, |
82 TrainingManager.fileErrorHandler_); | 122 TrainingManager.fileErrorHandler_); |
83 }; | 123 }; |
84 | 124 |
| 125 /** |
| 126 * Handles a request for the speaker model existence. |
| 127 */ |
| 128 TrainingManager.handleSpeakerModelExists = function() { |
| 129 window.webkitRequestFileSystem(PERSISTENT, |
| 130 hotword.constants.FILE_SYSTEM_SIZE_BYTES, |
| 131 TrainingManager.speakerModelExists_, |
| 132 TrainingManager.fileErrorHandler_); |
| 133 }; |
| 134 |
85 TrainingManager.prototype = { | 135 TrainingManager.prototype = { |
86 __proto__: hotword.BaseSessionManager.prototype, | 136 __proto__: hotword.BaseSessionManager.prototype, |
87 | 137 |
88 /** @override */ | 138 /** @override */ |
89 enabled: function() { | 139 enabled: function() { |
90 return this.stateManager.isTrainingEnabled(); | 140 return this.stateManager.isTrainingEnabled(); |
91 }, | 141 }, |
92 | 142 |
93 /** @override */ | 143 /** @override */ |
94 updateListeners: function() { | 144 updateListeners: function() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 handleSpeakerModelSaved_: function() { | 195 handleSpeakerModelSaved_: function() { |
146 if (this.enabled()) | 196 if (this.enabled()) |
147 chrome.hotwordPrivate.notifySpeakerModelSaved(); | 197 chrome.hotwordPrivate.notifySpeakerModelSaved(); |
148 }, | 198 }, |
149 }; | 199 }; |
150 | 200 |
151 return { | 201 return { |
152 TrainingManager: TrainingManager | 202 TrainingManager: TrainingManager |
153 }; | 203 }; |
154 }); | 204 }); |
OLD | NEW |