Commit d7b7b200 authored by evliu's avatar evliu Committed by Commit Bot

Update SODA to take in a path to the language pack directory

This CL updates SODA to take in a path to the language pack direcotry
instead of a path to the dictation.ascii_proto config file. SODA will
instead choose the appropriate config file to use within the language
pack directory.

Google3-side changes: cl/326259391

Bug: 1124367
Change-Id: I3ec52682a1d22afe9077a9ddfdb02c054319fa14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391283Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#804122}
parent 4b8556b8
......@@ -29,7 +29,7 @@ namespace {
// The SHA256 of the SubjectPublicKeyInfo used to sign the component.
// The component id is: icnkogojpkfjeajonkmlplionaamopkf
const uint8_t kSODAPublicKeySHA256[32] = {
constexpr uint8_t kSODAPublicKeySHA256[32] = {
0x82, 0xda, 0xe6, 0xe9, 0xfa, 0x59, 0x40, 0x9e, 0xda, 0xcb, 0xfb,
0x8e, 0xd0, 0x0c, 0xef, 0xa5, 0xc0, 0x97, 0x00, 0x84, 0x1c, 0x21,
0xa6, 0xae, 0xc8, 0x1b, 0x87, 0xfb, 0x12, 0x27, 0x28, 0xb1};
......@@ -37,7 +37,7 @@ const uint8_t kSODAPublicKeySHA256[32] = {
static_assert(base::size(kSODAPublicKeySHA256) == crypto::kSHA256Length,
"Wrong hash length");
const char kSODAManifestName[] = "SODA Library";
constexpr char kSODAManifestName[] = "SODA Library";
} // namespace
......
......@@ -27,7 +27,7 @@ namespace {
// The SHA256 of the SubjectPublicKeyInfo used to sign the component.
// The component id is: oegebmmcimckjhkhbggblnkjloogjdfg
const uint8_t kSodaEnUsPublicKeySHA256[32] = {
constexpr uint8_t kSodaEnUsPublicKeySHA256[32] = {
0xe4, 0x64, 0x1c, 0xc2, 0x8c, 0x2a, 0x97, 0xa7, 0x16, 0x61, 0xbd,
0xa9, 0xbe, 0xe6, 0x93, 0x56, 0xf5, 0x05, 0x33, 0x9b, 0x8b, 0x0b,
0x02, 0xe2, 0x6b, 0x7e, 0x6c, 0x40, 0xa1, 0xd2, 0x7e, 0x18};
......@@ -35,10 +35,7 @@ const uint8_t kSodaEnUsPublicKeySHA256[32] = {
static_assert(base::size(kSodaEnUsPublicKeySHA256) == crypto::kSHA256Length,
"Wrong hash length");
const char kSodaEnUsManifestName[] = "SODA en-US Models";
constexpr base::FilePath::CharType kSodaEnUsConfigFileRelativePath[] =
FILE_PATH_LITERAL("SODAModels/dictation.ascii_proto");
constexpr char kSodaEnUsManifestName[] = "SODA en-US Models";
} // namespace
......@@ -70,7 +67,8 @@ void SodaEnUsComponentInstallerPolicy::UpdateSodaEnUsComponentOnDemand() {
bool SodaEnUsComponentInstallerPolicy::VerifyInstallation(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) const {
return base::PathExists(install_dir.Append(kSodaEnUsConfigFileRelativePath));
return base::PathExists(
install_dir.Append(speech::kSodaLanguagePackDirectoryRelativePath));
}
bool SodaEnUsComponentInstallerPolicy::
......@@ -128,8 +126,9 @@ std::vector<std::string> SodaEnUsComponentInstallerPolicy::GetMimeTypes()
void UpdateSodaEnUsInstallDirPref(PrefService* prefs,
const base::FilePath& install_dir) {
#if !defined(OS_ANDROID)
prefs->SetFilePath(prefs::kSodaEnUsConfigPath,
install_dir.Append(kSodaEnUsConfigFileRelativePath));
prefs->SetFilePath(
prefs::kSodaEnUsConfigPath,
install_dir.Append(speech::kSodaLanguagePackDirectoryRelativePath));
#endif
}
......
......@@ -27,7 +27,7 @@ namespace {
// The SHA256 of the SubjectPublicKeyInfo used to sign the component.
// The component id is: onhpjgkfgajmkkeniaoflicgokpaebfa
const uint8_t kSodaJaJpPublicKeySHA256[32] = {
constexpr uint8_t kSodaJaJpPublicKeySHA256[32] = {
0xed, 0x7f, 0x96, 0xa5, 0x60, 0x9c, 0xaa, 0x4d, 0x80, 0xe5, 0xb8,
0x26, 0xea, 0xf0, 0x41, 0x50, 0x09, 0x52, 0xa4, 0xb3, 0x1e, 0x6a,
0x8e, 0x24, 0x99, 0xde, 0x51, 0x14, 0xc4, 0x3c, 0xfa, 0x48};
......@@ -35,10 +35,7 @@ const uint8_t kSodaJaJpPublicKeySHA256[32] = {
static_assert(base::size(kSodaJaJpPublicKeySHA256) == crypto::kSHA256Length,
"Wrong hash length");
const char kSodaJaJpManifestName[] = "SODA ja-JP Models";
constexpr base::FilePath::CharType kSodaJaJpConfigFileRelativePath[] =
FILE_PATH_LITERAL("SODAModels/dictation.ascii_proto");
constexpr char kSodaJaJpManifestName[] = "SODA ja-JP Models";
} // namespace
......@@ -70,7 +67,8 @@ void SodaJaJpComponentInstallerPolicy::UpdateSodaJaJpComponentOnDemand() {
bool SodaJaJpComponentInstallerPolicy::VerifyInstallation(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) const {
return base::PathExists(install_dir.Append(kSodaJaJpConfigFileRelativePath));
return base::PathExists(
install_dir.Append(speech::kSodaLanguagePackDirectoryRelativePath));
}
bool SodaJaJpComponentInstallerPolicy::
......@@ -128,8 +126,9 @@ std::vector<std::string> SodaJaJpComponentInstallerPolicy::GetMimeTypes()
void UpdateSodaJaJpInstallDirPref(PrefService* prefs,
const base::FilePath& install_dir) {
#if !defined(OS_ANDROID)
prefs->SetFilePath(prefs::kSodaJaJpConfigPath,
install_dir.Append(kSodaJaJpConfigFileRelativePath));
prefs->SetFilePath(
prefs::kSodaJaJpConfigPath,
install_dir.Append(speech::kSodaLanguagePackDirectoryRelativePath));
#endif
}
......
......@@ -131,11 +131,11 @@ void SpeechRecognitionRecognizerImpl::SendAudioToSpeechRecognitionService(
soda_client_->DidAudioPropertyChange(sample_rate, channel_count)) {
// Initialize the SODA instance.
auto api_key = google_apis::GetSodaAPIKey();
std::string config_file_path = config_path_.AsUTF8Unsafe();
std::string language_pack_directory = config_path_.AsUTF8Unsafe();
SodaConfig config;
config.channel_count = channel_count;
config.sample_rate = sample_rate;
config.config_file = config_file_path.c_str();
config.language_pack_directory = language_pack_directory.c_str();
config.callback = RecognitionCallback;
config.callback_handle = this;
config.api_key = api_key.c_str();
......
......@@ -32,6 +32,9 @@ constexpr base::FilePath::CharType kSodaEnUsInstallationRelativePath[] =
constexpr base::FilePath::CharType kSodaJaJpInstallationRelativePath[] =
FILE_PATH_LITERAL("SODALanguagePacks/ja-JP");
constexpr base::FilePath::CharType kSodaLanguagePackDirectoryRelativePath[] =
FILE_PATH_LITERAL("SODAModels");
const base::FilePath GetSodaDirectory() {
base::FilePath components_dir;
base::PathService::Get(component_updater::DIR_COMPONENT_USER,
......
......@@ -15,6 +15,9 @@ enum class LanguageCode {
kJaJp = 2,
};
// Location of the libsoda binary within the SODA installation directory.
extern const base::FilePath::CharType kSodaBinaryRelativePath[];
// Location of the SODA component relative to the components directory.
extern const base::FilePath::CharType kSodaInstallationRelativePath[];
......@@ -30,15 +33,9 @@ extern const base::FilePath::CharType kSodaEnUsInstallationRelativePath[];
// directory.
extern const base::FilePath::CharType kSodaJaJpInstallationRelativePath[];
// Location of the libsoda binary within the SODA installation directory.
extern const base::FilePath::CharType kSodaBinaryRelativePath[];
// Location of the en-US SODA config file within the SODA installation
// directory. Note: SODA is currently only available in English.
extern const base::FilePath::CharType kSodaEnUsConfigFileRelativePath[];
// Location of the ja-JP SODA config file within the SODA installation
extern const base::FilePath::CharType kSodaJaJpConfigFileRelativePath[];
// Location of the SODA models directory relative to the language pack
// installation directory.
extern const base::FilePath::CharType kSodaLanguagePackDirectoryRelativePath[];
// Get the absolute path of the SODA component directory.
const base::FilePath GetSodaDirectory();
......
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