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() { ...@@ -39,7 +39,7 @@ cr.define('speech', function() {
/** /**
* @constructor * @constructor
*/ */
function PluginManager(onReady, onRecognized) { function PluginManager(prefix, onReady, onRecognized) {
this.state = PluginState.UNINITIALIZED; this.state = PluginState.UNINITIALIZED;
this.onReady_ = onReady; this.onReady_ = onReady;
this.onRecognized_ = onRecognized; this.onRecognized_ = onRecognized;
...@@ -50,7 +50,7 @@ cr.define('speech', function() { ...@@ -50,7 +50,7 @@ cr.define('speech', function() {
recognizer = document.createElement('EMBED'); recognizer = document.createElement('EMBED');
recognizer.id = 'recognizer'; recognizer.id = 'recognizer';
recognizer.type = 'application/x-nacl'; recognizer.type = 'application/x-nacl';
recognizer.src = 'chrome://app-list/greconacl.nmf'; recognizer.src = 'chrome://app-list/hotword_' + prefix + '.nmf';
recognizer.width = '1'; recognizer.width = '1';
recognizer.height = '1'; recognizer.height = '1';
document.body.appendChild(recognizer); document.body.appendChild(recognizer);
......
...@@ -26,6 +26,22 @@ cr.define('speech', function() { ...@@ -26,6 +26,22 @@ cr.define('speech', function() {
STOPPING: 'STOPPING' 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 * @constructor
*/ */
...@@ -78,7 +94,6 @@ cr.define('speech', function() { ...@@ -78,7 +94,6 @@ cr.define('speech', function() {
this.pluginManager_.startRecognizer(); this.pluginManager_.startRecognizer();
this.audioManager_.start(); this.audioManager_.start();
this.setState_(SpeechState.HOTWORD_RECOGNIZING); this.setState_(SpeechState.HOTWORD_RECOGNIZING);
chrome.send('setHotwordRecognizerState', [true]);
}; };
/** /**
...@@ -163,11 +178,17 @@ cr.define('speech', function() { ...@@ -163,11 +178,17 @@ cr.define('speech', function() {
if (enabled) { if (enabled) {
if (recognizer) if (recognizer)
return; return;
if (!this.naclArch)
return;
var prefix = getHotwordPrefix();
var pluginManager = new speech.PluginManager( var pluginManager = new speech.PluginManager(
prefix,
this.onHotwordRecognizerReady_.bind(this), this.onHotwordRecognizerReady_.bind(this),
this.onHotwordRecognized_.bind(this)); this.onHotwordRecognized_.bind(this));
pluginManager.scheduleInitialize( var modelUrl = 'chrome://app-list/_platform_specific/' + this.naclArch +
this.audioManager_.sampleRate, 'chrome://app-list/hotword.data'); '_' + prefix + '/hotword.data';
pluginManager.scheduleInitialize(this.audioManager_.sampleRate, modelUrl);
} else { } else {
if (!recognizer) if (!recognizer)
return; return;
...@@ -180,6 +201,15 @@ cr.define('speech', function() { ...@@ -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. * Called when the app-list bubble is shown.
* *
......
...@@ -75,6 +75,14 @@ cr.define('appList.startPage', function() { ...@@ -75,6 +75,14 @@ cr.define('appList.startPage', function() {
speechManager.setHotwordEnabled(enabled); 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. * Invoked when the app-list bubble is shown.
* *
...@@ -103,6 +111,7 @@ cr.define('appList.startPage', function() { ...@@ -103,6 +111,7 @@ cr.define('appList.startPage', function() {
initialize: initialize, initialize: initialize,
setRecommendedApps: setRecommendedApps, setRecommendedApps: setRecommendedApps,
setHotwordEnabled: setHotwordEnabled, setHotwordEnabled: setHotwordEnabled,
setNaclArch: setNaclArch,
onAppListShown: onAppListShown, onAppListShown: onAppListShown,
onAppListHidden: onAppListHidden, onAppListHidden: onAppListHidden,
toggleSpeechRecognition: toggleSpeechRecognition toggleSpeechRecognition: toggleSpeechRecognition
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.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/profiles/profile.h"
#include "chrome/browser/search/hotword_service.h" #include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
...@@ -166,6 +167,10 @@ void StartPageHandler::HandleInitialize(const base::ListValue* args) { ...@@ -166,6 +167,10 @@ void StartPageHandler::HandleInitialize(const base::ListValue* args) {
} }
#endif #endif
web_ui()->CallJavascriptFunction(
"appList.startPage.setNaclArch",
base::StringValue(chrome::OmahaQueryParams::GetNaclArch()));
if (!app_list::switches::IsExperimentalAppListEnabled()) { if (!app_list::switches::IsExperimentalAppListEnabled()) {
web_ui()->CallJavascriptFunction( web_ui()->CallJavascriptFunction(
"appList.startPage.onAppListShown", "appList.startPage.onAppListShown",
......
...@@ -24,12 +24,9 @@ ...@@ -24,12 +24,9 @@
namespace app_list { namespace app_list {
namespace { namespace {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
const char* kHotwordFilenames[] = { const char* kHotwordFilePrefixes[] = {
"greconacl.nmf", "hotword_",
"hotword.data", "_platform_specific/",
"_platform_specific/arm/hotword_arm.nexe",
"_platform_specific/x86-32/hotword_x86_32.nexe",
"_platform_specific/x86-64/hotword_x86_64.nexe",
}; };
void LoadModelData(const base::FilePath& base_dir, void LoadModelData(const base::FilePath& base_dir,
...@@ -53,8 +50,8 @@ bool HandleHotwordFilesResourceFilter( ...@@ -53,8 +50,8 @@ bool HandleHotwordFilesResourceFilter(
if (!extension) if (!extension)
return false; return false;
for (size_t i = 0; i < arraysize(kHotwordFilenames); ++i) { for (size_t i = 0; i < arraysize(kHotwordFilePrefixes); ++i) {
if (path == kHotwordFilenames[i]) { if (path.find(kHotwordFilePrefixes[i]) == 0) {
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::FILE, content::BrowserThread::FILE,
FROM_HERE, 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