Chromium Code Reviews| 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 success event on mounting the file system checks for the | |
|
Anand Mistry (off Chromium)
2015/03/23 03:10:03
...mounting the file system _and_ checks for...
kcarattini
2015/03/23 22:59:39
Done.
| |
| 78 * existence of the speaker model. | |
| 79 * @param {FileSystem} fs The FileSystem object. | |
| 80 * @private | |
| 81 */ | |
| 82 TrainingManager.speakerModelExists_ = function(fs) { | |
| 83 fs.root.getFile(hotword.constants.SPEAKER_MODEL_FILE_NAME, {create: false}, | |
| 84 TrainingManager.sendSpeakerModelExistsResponse_, | |
| 85 TrainingManager.fileErrorHandler_); | |
| 86 }; | |
| 87 | |
| 88 /** | |
| 89 * Sends a response throught the HotwordPrivateApi indicating whether | |
|
Anand Mistry (off Chromium)
2015/03/23 03:10:03
throught
kcarattini
2015/03/23 22:59:40
Done.
| |
| 90 * the speaker model exists. | |
| 91 * @param {FileEntry} fileEntry The FileEntry object. | |
| 92 * @private | |
| 93 */ | |
| 94 TrainingManager.sendSpeakerModelExistsResponse_ = function(fileEntry) { | |
| 95 if (fileEntry.isFile) { | |
| 96 hotword.debug('File found: ' + fileEntry.fullPath); | |
| 97 if (hotword.DEBUG || window.localStorage['hotword.DEBUG']) { | |
| 98 fileEntry.getMetadata(function(md) { | |
| 99 hotword.debug('File size: ' + md.size); | |
| 100 }); | |
| 101 } | |
| 102 } | |
| 103 chrome.hotwordPrivate.speakerModelExistsResult(fileEntry.isFile); | |
| 104 }; | |
| 105 | |
| 106 /** | |
| 76 * Handles a request to delete the speaker model. | 107 * Handles a request to delete the speaker model. |
| 77 */ | 108 */ |
| 78 TrainingManager.handleDeleteSpeakerModel = function() { | 109 TrainingManager.handleDeleteSpeakerModel = function() { |
| 79 window.webkitRequestFileSystem(PERSISTENT, | 110 window.webkitRequestFileSystem(PERSISTENT, |
| 80 hotword.constants.FILE_SYSTEM_SIZE_BYTES, | 111 hotword.constants.FILE_SYSTEM_SIZE_BYTES, |
| 81 TrainingManager.onRequestFileSystemSuccess_, | 112 TrainingManager.deleteFiles_, |
| 82 TrainingManager.fileErrorHandler_); | 113 TrainingManager.fileErrorHandler_); |
| 83 }; | 114 }; |
| 84 | 115 |
| 116 /** | |
| 117 * Handles a request for the speaker model existence. | |
| 118 */ | |
| 119 TrainingManager.handleSpeakerModelExists = function() { | |
| 120 window.webkitRequestFileSystem(PERSISTENT, | |
| 121 hotword.constants.FILE_SYSTEM_SIZE_BYTES, | |
| 122 TrainingManager.speakerModelExists_, | |
| 123 TrainingManager.fileErrorHandler_); | |
| 124 }; | |
| 125 | |
| 85 TrainingManager.prototype = { | 126 TrainingManager.prototype = { |
| 86 __proto__: hotword.BaseSessionManager.prototype, | 127 __proto__: hotword.BaseSessionManager.prototype, |
| 87 | 128 |
| 88 /** @override */ | 129 /** @override */ |
| 89 enabled: function() { | 130 enabled: function() { |
| 90 return this.stateManager.isTrainingEnabled(); | 131 return this.stateManager.isTrainingEnabled(); |
| 91 }, | 132 }, |
| 92 | 133 |
| 93 /** @override */ | 134 /** @override */ |
| 94 updateListeners: function() { | 135 updateListeners: function() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 handleSpeakerModelSaved_: function() { | 186 handleSpeakerModelSaved_: function() { |
| 146 if (this.enabled()) | 187 if (this.enabled()) |
| 147 chrome.hotwordPrivate.notifySpeakerModelSaved(); | 188 chrome.hotwordPrivate.notifySpeakerModelSaved(); |
| 148 }, | 189 }, |
| 149 }; | 190 }; |
| 150 | 191 |
| 151 return { | 192 return { |
| 152 TrainingManager: TrainingManager | 193 TrainingManager: TrainingManager |
| 153 }; | 194 }; |
| 154 }); | 195 }); |
| OLD | NEW |