Commit bdd62838 authored by mukai@chromium.org's avatar mukai@chromium.org

Modifies handling of hotword NaCl module.

This will break the behavior with the older version of the hotword,
but actually that is fine because anyways the app-launcher hasn't
worked well with the older version for other reasons.

BUG=356873
R=xiyuan@chromium.org
TEST=manually

Review URL: https://codereview.chromium.org/229323003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262911 0039d316-1c4b-4281-b951-d872f2087c98
parent c8ccc41d
......@@ -39,7 +39,7 @@ cr.define('speech', function() {
/**
* @constructor
*/
function PluginManager(onReady, onRecognized) {
function PluginManager(prefix, onReady, onRecognized) {
this.state = PluginState.UNINITIALIZED;
this.onReady_ = onReady;
this.onRecognized_ = onRecognized;
......@@ -50,7 +50,7 @@ cr.define('speech', function() {
recognizer = document.createElement('EMBED');
recognizer.id = 'recognizer';
recognizer.type = 'application/x-nacl';
recognizer.src = 'chrome://app-list/greconacl.nmf';
recognizer.src = 'chrome://app-list/hotword_' + prefix + '.nmf';
recognizer.width = '1';
recognizer.height = '1';
document.body.appendChild(recognizer);
......
......@@ -26,6 +26,22 @@ cr.define('speech', function() {
STOPPING: 'STOPPING'
};
/**
* Checks the prefix for the hotword module based on the language. This is
* fragile if the file structure has changed.
*/
function getHotwordPrefix() {
var prefix = navigator.language.toLowerCase();
if (prefix == 'en-gb')
return prefix;
var hyphen = prefix.indexOf('-');
if (hyphen >= 0)
prefix = prefix.substr(0, hyphen);
if (prefix == 'en')
prefix = '';
return prefix;
}
/**
* @constructor
*/
......@@ -78,7 +94,6 @@ cr.define('speech', function() {
this.pluginManager_.startRecognizer();
this.audioManager_.start();
this.setState_(SpeechState.HOTWORD_RECOGNIZING);
chrome.send('setHotwordRecognizerState', [true]);
};
/**
......@@ -163,11 +178,17 @@ cr.define('speech', function() {
if (enabled) {
if (recognizer)
return;
if (!this.naclArch)
return;
var prefix = getHotwordPrefix();
var pluginManager = new speech.PluginManager(
prefix,
this.onHotwordRecognizerReady_.bind(this),
this.onHotwordRecognized_.bind(this));
pluginManager.scheduleInitialize(
this.audioManager_.sampleRate, 'chrome://app-list/hotword.data');
var modelUrl = 'chrome://app-list/_platform_specific/' + this.naclArch +
'_' + prefix + '/hotword.data';
pluginManager.scheduleInitialize(this.audioManager_.sampleRate, modelUrl);
} else {
if (!recognizer)
return;
......@@ -180,6 +201,15 @@ cr.define('speech', function() {
}
};
/**
* Sets the NaCl architecture for the hotword module.
*
* @param {string} arch The architecture.
*/
SpeechManager.prototype.setNaclArch = function(arch) {
this.naclArch = arch;
};
/**
* Called when the app-list bubble is shown.
*
......
......@@ -75,6 +75,14 @@ cr.define('appList.startPage', function() {
speechManager.setHotwordEnabled(enabled);
}
/**
* Sets the architecture of NaCl module to be loaded for hotword.
* @param {string} arch The architecture.
*/
function setNaclArch(arch) {
speechManager.setNaclArch(arch);
}
/**
* Invoked when the app-list bubble is shown.
*
......@@ -103,6 +111,7 @@ cr.define('appList.startPage', function() {
initialize: initialize,
setRecommendedApps: setRecommendedApps,
setHotwordEnabled: setHotwordEnabled,
setNaclArch: setNaclArch,
onAppListShown: onAppListShown,
onAppListHidden: onAppListHidden,
toggleSpeechRecognition: toggleSpeechRecognition
......
......@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/omaha_query_params/omaha_query_params.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
......@@ -166,6 +167,10 @@ void StartPageHandler::HandleInitialize(const base::ListValue* args) {
}
#endif
web_ui()->CallJavascriptFunction(
"appList.startPage.setNaclArch",
base::StringValue(chrome::OmahaQueryParams::GetNaclArch()));
if (!app_list::switches::IsExperimentalAppListEnabled()) {
web_ui()->CallJavascriptFunction(
"appList.startPage.onAppListShown",
......
......@@ -24,12 +24,9 @@
namespace app_list {
namespace {
#if defined(OS_CHROMEOS)
const char* kHotwordFilenames[] = {
"greconacl.nmf",
"hotword.data",
"_platform_specific/arm/hotword_arm.nexe",
"_platform_specific/x86-32/hotword_x86_32.nexe",
"_platform_specific/x86-64/hotword_x86_64.nexe",
const char* kHotwordFilePrefixes[] = {
"hotword_",
"_platform_specific/",
};
void LoadModelData(const base::FilePath& base_dir,
......@@ -53,8 +50,8 @@ bool HandleHotwordFilesResourceFilter(
if (!extension)
return false;
for (size_t i = 0; i < arraysize(kHotwordFilenames); ++i) {
if (path == kHotwordFilenames[i]) {
for (size_t i = 0; i < arraysize(kHotwordFilePrefixes); ++i) {
if (path.find(kHotwordFilePrefixes[i]) == 0) {
content::BrowserThread::PostTask(
content::BrowserThread::FILE,
FROM_HERE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment