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
3 // found in the LICENSE file.
5 cr.define('hotword.constants', function() {
9 * Number of seconds of audio to record when logging is enabled.
12 var AUDIO_LOG_SECONDS = 2;
15 * Hotword data shared module extension's ID.
18 var SHARED_MODULE_ID = 'lccekmodgklaepjeofjdjpbminllajkg';
21 * Path to shared module data.
24 var SHARED_MODULE_ROOT = '_modules/' + SHARED_MODULE_ID;
27 * Name used by the content scripts to create communications Ports.
30 var CLIENT_PORT_NAME = 'chwcpn';
33 * The field name to specify the command among pages.
36 var COMMAND_FIELD_NAME = 'cmd';
39 * The speaker model file name.
42 var SPEAKER_MODEL_FILE_NAME = 'speaker_model.data';
45 * The training utterance file name prefix.
48 var UTTERANCE_FILE_PREFIX = 'utterance-';
51 * The training utterance file extension.
54 var UTTERANCE_FILE_EXTENSION = '.raw';
57 * The number of training utterances required to train the speaker model.
60 var NUM_TRAINING_UTTERANCES = 3;
63 * The size of the file system requested for reading the speaker model and
64 * utterances. This number should always be larger than the combined file size,
65 * currently 576338 bytes as of February 2015.
68 var FILE_SYSTEM_SIZE_BYTES = 1048576;
71 * Time to wait for expected messages, in milliseconds.
81 * The URL of the files used by the plugin.
85 RECOGNIZER_CONFIG: 'hotword.data',
89 * Errors emitted by the NaClManager.
93 NACL_CRASH: 'nacl_crash',
98 * Event types supported by NaClManager.
104 SPEAKER_MODEL_SAVED: 'speaker model saved',
110 * Messages for communicating with the NaCl recognizer plugin. These must match
111 * constants in <google3>/hotword_plugin.c
116 SAMPLE_RATE_PREFIX: 'h',
120 BEGIN_SPEAKER_MODEL: 'b',
121 ADAPT_SPEAKER_MODEL: 'a',
122 FINISH_SPEAKER_MODEL: 'f',
123 SPEAKER_MODEL_SAVED: 'sm_saved',
124 REQUEST_MODEL: 'model',
125 MODEL_LOADED: 'model_loaded',
126 READY_FOR_AUDIO: 'audio',
128 HOTWORD_DETECTED: 'hotword',
129 MS_CONFIGURED: 'ms_configured',
134 * Messages sent from the injected scripts to the Google page.
137 var CommandToPage = {
138 HOTWORD_VOICE_TRIGGER: 'vt',
139 HOTWORD_STARTED: 'hs',
141 HOTWORD_TIMEOUT: 'ht',
146 * Messages sent from the Google page to the extension or to the
147 * injected script and then passed to the extension.
150 var CommandFromPage = {
154 SHOWING_HOTWORD_START: 'shs',
155 SHOWING_ERROR_MESSAGE: 'sem',
156 SHOWING_TIMEOUT_MESSAGE: 'stm',
157 CLICKED_RESUME: 'hcc',
158 CLICKED_RESTART: 'hcr',
159 CLICKED_DEBUG: 'hcd',
160 WAKE_UP_HELPER: 'wuh',
161 // Command specifically for the opt-in promo below this line.
162 // User has explicitly clicked 'no'.
163 CLICKED_NO_OPTIN: 'hcno',
164 // User has opted in.
165 CLICKED_OPTIN: 'hco',
166 // User clicked on the microphone.
171 * Source of a hotwording session request.
174 var SessionSource = {
175 LAUNCHER: 'launcher',
182 * The mode to start the hotword recognizer in.
185 var RecognizerStartMode = {
187 NEW_MODEL: 'new model',
188 ADAPT_MODEL: 'adapt model'
192 * MediaStream open success/errors to be reported via UMA.
193 * DO NOT remove or renumber values in this enum. Only add new ones.
196 var UmaMediaStreamOpenResult = {
200 PERMISSION_DENIED: 3,
201 CONSTRAINT_NOT_SATISFIED: 4,
205 SOURCE_UNAVAILABLE: 8,
206 PERMISSION_DISMISSED: 9,
208 DEVICES_NOT_FOUND: 11,
209 INVALID_SECURITY_ORIGIN: 12,
215 * DO NOT change these enum values.
219 TRIGGER: 'Hotword.HotwordTrigger',
220 MEDIA_STREAM_RESULT: 'Hotword.HotwordMediaStreamResult',
221 NACL_PLUGIN_LOAD_RESULT: 'Hotword.HotwordNaClPluginLoadResult',
222 NACL_MESSAGE_TIMEOUT: 'Hotword.HotwordNaClMessageTimeout',
223 TRIGGER_SOURCE: 'Hotword.HotwordTriggerSource'
227 * Message waited for by NaCl plugin, to be reported via UMA.
228 * DO NOT remove or renumber values in this enum. Only add new ones.
231 var UmaNaClMessageTimeout = {
242 * NaCl plugin load success/errors to be reported via UMA.
243 * DO NOT remove or renumber values in this enum. Only add new ones.
246 var UmaNaClPluginLoadResult = {
255 * Source of hotword triggering, to be reported via UMA.
256 * DO NOT remove or renumber values in this enum. Only add new ones.
259 var UmaTriggerSource = {
268 * The browser UI language.
271 var UI_LANGUAGE = (chrome.i18n && chrome.i18n.getUILanguage) ?
272 chrome.i18n.getUILanguage() : '';
275 AUDIO_LOG_SECONDS: AUDIO_LOG_SECONDS,
276 CLIENT_PORT_NAME: CLIENT_PORT_NAME,
277 COMMAND_FIELD_NAME: COMMAND_FIELD_NAME,
278 FILE_SYSTEM_SIZE_BYTES: FILE_SYSTEM_SIZE_BYTES,
279 NUM_TRAINING_UTTERANCES: NUM_TRAINING_UTTERANCES,
280 SHARED_MODULE_ID: SHARED_MODULE_ID,
281 SHARED_MODULE_ROOT: SHARED_MODULE_ROOT,
282 SPEAKER_MODEL_FILE_NAME: SPEAKER_MODEL_FILE_NAME,
283 UI_LANGUAGE: UI_LANGUAGE,
284 UTTERANCE_FILE_EXTENSION: UTTERANCE_FILE_EXTENSION,
285 UTTERANCE_FILE_PREFIX: UTTERANCE_FILE_PREFIX,
286 CommandToPage: CommandToPage,
287 CommandFromPage: CommandFromPage,
291 NaClPlugin: NaClPlugin,
292 RecognizerStartMode: RecognizerStartMode,
293 SessionSource: SessionSource,
294 TimeoutMs: TimeoutMs,
295 UmaMediaStreamOpenResult: UmaMediaStreamOpenResult,
296 UmaMetrics: UmaMetrics,
297 UmaNaClMessageTimeout: UmaNaClMessageTimeout,
298 UmaNaClPluginLoadResult: UmaNaClPluginLoadResult,
299 UmaTriggerSource: UmaTriggerSource