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 * Timeout in seconds, for detecting false positives with a hotword stream.
18 var HOTWORD_STREAM_TIMEOUT_SECONDS = 2;
21 * Hotword data shared module extension's ID.
24 var SHARED_MODULE_ID = 'lccekmodgklaepjeofjdjpbminllajkg';
27 * Path to shared module data.
30 var SHARED_MODULE_ROOT = '_modules/' + SHARED_MODULE_ID;
33 * Name used by the content scripts to create communications Ports.
36 var CLIENT_PORT_NAME = 'chwcpn';
39 * The field name to specify the command among pages.
42 var COMMAND_FIELD_NAME = 'cmd';
45 * The speaker model file name.
48 var SPEAKER_MODEL_FILE_NAME = 'speaker_model.data';
51 * The training utterance file name prefix.
54 var UTTERANCE_FILE_PREFIX = 'utterance-';
57 * The training utterance file extension.
60 var UTTERANCE_FILE_EXTENSION = '.raw';
63 * The number of training utterances required to train the speaker model.
66 var NUM_TRAINING_UTTERANCES = 3;
69 * The size of the file system requested for reading the speaker model and
70 * utterances. This number should always be larger than the combined file size,
71 * currently 576338 bytes as of February 2015.
74 var FILE_SYSTEM_SIZE_BYTES = 1048576;
77 * Time to wait for expected messages, in milliseconds.
87 * The URL of the files used by the plugin.
91 RECOGNIZER_CONFIG: 'hotword.data',
95 * Errors emitted by the NaClManager.
99 NACL_CRASH: 'nacl_crash',
104 * Event types supported by NaClManager.
110 SPEAKER_MODEL_SAVED: 'speaker model saved',
116 * Messages for communicating with the NaCl recognizer plugin. These must match
117 * constants in <google3>/hotword_plugin.c
122 SAMPLE_RATE_PREFIX: 'h',
127 BEGIN_SPEAKER_MODEL: 'b',
128 ADAPT_SPEAKER_MODEL: 'a',
129 FINISH_SPEAKER_MODEL: 'f',
130 SPEAKER_MODEL_SAVED: 'sm_saved',
131 REQUEST_MODEL: 'model',
132 MODEL_LOADED: 'model_loaded',
133 READY_FOR_AUDIO: 'audio',
135 HOTWORD_DETECTED: 'hotword',
136 MS_CONFIGURED: 'ms_configured',
141 * Messages sent from the injected scripts to the Google page.
144 var CommandToPage = {
145 HOTWORD_VOICE_TRIGGER: 'vt',
146 HOTWORD_STARTED: 'hs',
148 HOTWORD_TIMEOUT: 'ht',
153 * Messages sent from the Google page to the extension or to the
154 * injected script and then passed to the extension.
157 var CommandFromPage = {
161 SHOWING_HOTWORD_START: 'shs',
162 SHOWING_ERROR_MESSAGE: 'sem',
163 SHOWING_TIMEOUT_MESSAGE: 'stm',
164 CLICKED_RESUME: 'hcc',
165 CLICKED_RESTART: 'hcr',
166 CLICKED_DEBUG: 'hcd',
167 WAKE_UP_HELPER: 'wuh',
168 // Command specifically for the opt-in promo below this line.
169 // User has explicitly clicked 'no'.
170 CLICKED_NO_OPTIN: 'hcno',
171 // User has opted in.
172 CLICKED_OPTIN: 'hco',
173 // User clicked on the microphone.
178 * Source of a hotwording session request.
181 var SessionSource = {
182 LAUNCHER: 'launcher',
189 * The mode to start the hotword recognizer in.
192 var RecognizerStartMode = {
194 NEW_MODEL: 'new model',
195 ADAPT_MODEL: 'adapt model'
199 * MediaStream open success/errors to be reported via UMA.
200 * DO NOT remove or renumber values in this enum. Only add new ones.
203 var UmaMediaStreamOpenResult = {
207 PERMISSION_DENIED: 3,
208 CONSTRAINT_NOT_SATISFIED: 4,
212 SOURCE_UNAVAILABLE: 8,
213 PERMISSION_DISMISSED: 9,
215 DEVICES_NOT_FOUND: 11,
216 INVALID_SECURITY_ORIGIN: 12,
222 * DO NOT change these enum values.
226 TRIGGER: 'Hotword.HotwordTrigger',
227 MEDIA_STREAM_RESULT: 'Hotword.HotwordMediaStreamResult',
228 NACL_PLUGIN_LOAD_RESULT: 'Hotword.HotwordNaClPluginLoadResult',
229 NACL_MESSAGE_TIMEOUT: 'Hotword.HotwordNaClMessageTimeout',
230 TRIGGER_SOURCE: 'Hotword.HotwordTriggerSource'
234 * Message waited for by NaCl plugin, to be reported via UMA.
235 * DO NOT remove or renumber values in this enum. Only add new ones.
238 var UmaNaClMessageTimeout = {
249 * NaCl plugin load success/errors to be reported via UMA.
250 * DO NOT remove or renumber values in this enum. Only add new ones.
253 var UmaNaClPluginLoadResult = {
262 * Source of hotword triggering, to be reported via UMA.
263 * DO NOT remove or renumber values in this enum. Only add new ones.
266 var UmaTriggerSource = {
275 * The browser UI language.
278 var UI_LANGUAGE = (chrome.i18n && chrome.i18n.getUILanguage) ?
279 chrome.i18n.getUILanguage() : '';
282 AUDIO_LOG_SECONDS: AUDIO_LOG_SECONDS,
283 CLIENT_PORT_NAME: CLIENT_PORT_NAME,
284 COMMAND_FIELD_NAME: COMMAND_FIELD_NAME,
285 FILE_SYSTEM_SIZE_BYTES: FILE_SYSTEM_SIZE_BYTES,
286 HOTWORD_STREAM_TIMEOUT_SECONDS: HOTWORD_STREAM_TIMEOUT_SECONDS,
287 NUM_TRAINING_UTTERANCES: NUM_TRAINING_UTTERANCES,
288 SHARED_MODULE_ID: SHARED_MODULE_ID,
289 SHARED_MODULE_ROOT: SHARED_MODULE_ROOT,
290 SPEAKER_MODEL_FILE_NAME: SPEAKER_MODEL_FILE_NAME,
291 UI_LANGUAGE: UI_LANGUAGE,
292 UTTERANCE_FILE_EXTENSION: UTTERANCE_FILE_EXTENSION,
293 UTTERANCE_FILE_PREFIX: UTTERANCE_FILE_PREFIX,
294 CommandToPage: CommandToPage,
295 CommandFromPage: CommandFromPage,
299 NaClPlugin: NaClPlugin,
300 RecognizerStartMode: RecognizerStartMode,
301 SessionSource: SessionSource,
302 TimeoutMs: TimeoutMs,
303 UmaMediaStreamOpenResult: UmaMediaStreamOpenResult,
304 UmaMetrics: UmaMetrics,
305 UmaNaClMessageTimeout: UmaNaClMessageTimeout,
306 UmaNaClPluginLoadResult: UmaNaClPluginLoadResult,
307 UmaTriggerSource: UmaTriggerSource