diff options
author | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 16:24:45 +0000 |
---|---|---|
committer | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 16:24:45 +0000 |
commit | 4535dbc797d69d7e9e2a5ecff93ca94c8878a5f0 (patch) | |
tree | dafc78abbf21cbe1916cd809e3ef0309d89d7d2a /chrome/browser/extensions/extension_tts_api.cc | |
parent | 68daddd38c577e36367456becd005daaf6f2934a (diff) | |
download | chromium_src-4535dbc797d69d7e9e2a5ecff93ca94c8878a5f0.zip chromium_src-4535dbc797d69d7e9e2a5ecff93ca94c8878a5f0.tar.gz chromium_src-4535dbc797d69d7e9e2a5ecff93ca94c8878a5f0.tar.bz2 |
Revert 62283 - Refactored TTS extension code so that the platform-specific TTS
implementation code is separate from the extension API code.
That will make it easier to add more functionality that's shared
by all platforms next.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3640001
TBR=dmazzoni@chromium.org
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62284 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_tts_api.cc')
-rw-r--r-- | chrome/browser/extensions/extension_tts_api.cc | 96 |
1 files changed, 56 insertions, 40 deletions
diff --git a/chrome/browser/extensions/extension_tts_api.cc b/chrome/browser/extensions/extension_tts_api.cc index b022ec0..ba9c2f8 100644 --- a/chrome/browser/extensions/extension_tts_api.cc +++ b/chrome/browser/extensions/extension_tts_api.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,11 +6,16 @@ #include <string> -#include "base/float_util.h" #include "base/values.h" +#include "base/string_number_conversions.h" + +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/speech_synthesis_library.h" namespace util = extension_tts_api_util; +using base::DoubleToString; + namespace { const char kCrosLibraryNotLoadedError[] = "Cros shared library not loaded."; @@ -18,57 +23,68 @@ namespace { bool ExtensionTtsSpeakFunction::RunImpl() { std::string utterance; - std::string language; - std::string gender; - double rate = -1.0; - double pitch = -1.0; - double volume = -1.0; - + std::string options = ""; DictionaryValue* speak_options = NULL; EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &utterance)); - if (args_->GetDictionary(1, &speak_options)) { - if (speak_options->HasKey(util::kLanguageNameKey)) { - speak_options->GetString(util::kLanguageNameKey, &language); + std::string str_value; + double real_value; + if (speak_options->HasKey(util::kLanguageNameKey) && + speak_options->GetString(util::kLanguageNameKey, &str_value)) { + util::AppendSpeakOption( + std::string(util::kNameKey), str_value, &options); } - - if (speak_options->HasKey(util::kGenderKey)) { - speak_options->GetString(util::kGenderKey, &gender); + if (speak_options->HasKey(util::kGenderKey) && + speak_options->GetString(util::kGenderKey, &str_value)) { + util::AppendSpeakOption( + std::string(util::kGenderKey), str_value, &options); } - - if (util::ReadNumberByKey(speak_options, util::kRateKey, &rate)) { - if (!base::IsFinite(rate) || rate < 0.0 || rate > 1.0) { - rate = -1.0; - } + if (util::ReadNumberByKey(speak_options, util::kRateKey, &real_value)) { + // The TTS service allows a range of 0 to 5 for speech rate. + util::AppendSpeakOption(std::string(util::kRateKey), + DoubleToString(real_value * 5), &options); } - - if (util::ReadNumberByKey(speak_options, util::kPitchKey, &pitch)) { - if (!base::IsFinite(pitch) || pitch < 0.0 || pitch > 1.0) { - pitch = -1.0; - } + if (util::ReadNumberByKey(speak_options, util::kPitchKey, &real_value)) { + // The TTS service allows a range of 0 to 2 for speech pitch. + util::AppendSpeakOption(std::string(util::kPitchKey), + DoubleToString(real_value * 2), &options); } - - if (util::ReadNumberByKey(speak_options, util::kVolumeKey, &volume)) { - if (!base::IsFinite(volume) || volume < 0.0 || volume > 1.0) { - volume = -1.0; - } + if (util::ReadNumberByKey(speak_options, util::kVolumeKey, &real_value)) { + // The TTS service allows a range of 0 to 5 for speech volume. + util::AppendSpeakOption(std::string(util::kVolumeKey), + DoubleToString(real_value * 5), &options); } } - - ExtensionTtsPlatformImpl* impl = ExtensionTtsPlatformImpl::GetInstance(); - impl->clear_error(); - return impl->Speak(utterance, language, gender, rate, pitch, volume); + if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { + if (!options.empty()) { + chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> + SetSpeakProperties(options.c_str()); + } + bool ret = chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> + Speak(utterance.c_str()); + result_.reset(); + return ret; + } + error_ = kCrosLibraryNotLoadedError; + return false; } bool ExtensionTtsStopSpeakingFunction::RunImpl() { - ExtensionTtsPlatformImpl* impl = ExtensionTtsPlatformImpl::GetInstance(); - impl->clear_error(); - return impl->StopSpeaking(); + if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { + return chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> + StopSpeaking(); + } + error_ = kCrosLibraryNotLoadedError; + return false; } bool ExtensionTtsIsSpeakingFunction::RunImpl() { - ExtensionTtsPlatformImpl* impl = ExtensionTtsPlatformImpl::GetInstance(); - impl->clear_error(); - result_.reset(Value::CreateBooleanValue(impl->IsSpeaking())); - return true; + if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { + result_.reset(Value::CreateBooleanValue( + chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> + IsSpeaking())); + return true; + } + error_ = kCrosLibraryNotLoadedError; + return false; } |