summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchaitanyag@chromium.org <chaitanyag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 00:37:26 +0000
committerchaitanyag@chromium.org <chaitanyag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 00:37:26 +0000
commit0eb8aa7a9651c8303f9911a3d7a50dd02df99660 (patch)
tree60fae7690a3114f32f2ba2dabaa740a7edd9fb83
parentbdff2897e47fbeb5fe26e369f8788c62d9c7c6d0 (diff)
downloadchromium_src-0eb8aa7a9651c8303f9911a3d7a50dd02df99660.zip
chromium_src-0eb8aa7a9651c8303f9911a3d7a50dd02df99660.tar.gz
chromium_src-0eb8aa7a9651c8303f9911a3d7a50dd02df99660.tar.bz2
Add code to support options for TTS speak.
Review URL: http://codereview.chromium.org/3116019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56788 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_tts_api.cc65
-rw-r--r--chrome/common/extensions/api/extension_api.json6
2 files changed, 68 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_tts_api.cc b/chrome/browser/extensions/extension_tts_api.cc
index 1cfdd43..47168af 100644
--- a/chrome/browser/extensions/extension_tts_api.cc
+++ b/chrome/browser/extensions/extension_tts_api.cc
@@ -7,19 +7,84 @@
#include <string>
#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"
+using base::DoubleToString;
+
+const char kNameKey[] = "name";
+const char kLanguageNameKey[] = "languageName";
+const char kGenderKey[] = "gender";
+const char kRateKey[] = "rate";
+const char kPitchKey[] = "pitch";
+const char kVolumeKey[] = "volume";
+const char kEqualStr[] = "=";
+const char kDelimiter[] = ";";
+
namespace {
const char kCrosLibraryNotLoadedError[] =
"Cros shared library not loaded.";
+
+ bool ReadNumberByKey(DictionaryValue* dict, const char* key,
+ double* ret_value) {
+ Value* value;
+ dict->Get(key, &value);
+ if (value->IsType(Value::TYPE_INTEGER)) {
+ int int_value;
+ if (!dict->GetInteger(key, &int_value))
+ return false;
+ *ret_value = int_value;
+ } else if (value->IsType(Value::TYPE_REAL)) {
+ if (!dict->GetReal(key, ret_value))
+ return false;
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ void AppendSpeakOption(std::string key, std::string value,
+ std::string* options) {
+ *options += key + kEqualStr + value + kDelimiter;
+ }
};
bool ExtensionTtsSpeakFunction::RunImpl() {
std::string utterance;
+ std::string options = "";
+ DictionaryValue* speak_options = NULL;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &utterance));
+ if (args_->GetDictionary(1, &speak_options)) {
+ std::string str_value;
+ double real_value;
+ if (speak_options->HasKey(kLanguageNameKey) &&
+ speak_options->GetString(kLanguageNameKey, &str_value)) {
+ AppendSpeakOption(std::string(kNameKey), str_value, &options);
+ }
+ if (speak_options->HasKey(kGenderKey) &&
+ speak_options->GetString(kGenderKey, &str_value)) {
+ AppendSpeakOption(std::string(kGenderKey), str_value, &options);
+ }
+ if (ReadNumberByKey(speak_options, kRateKey, &real_value))
+ // The TTS service allows a range of 0 to 5 for speech rate.
+ AppendSpeakOption(std::string(kRateKey),
+ DoubleToString(real_value * 5), &options);
+ if (ReadNumberByKey(speak_options, kPitchKey, &real_value))
+ // The TTS service allows a range of 0 to 2 for speech pitch.
+ AppendSpeakOption(std::string(kPitchKey),
+ DoubleToString(real_value * 2), &options);
+ if (ReadNumberByKey(speak_options, kVolumeKey, &real_value))
+ // The TTS service allows a range of 0 to 5 for speech volume.
+ AppendSpeakOption(std::string(kVolumeKey),
+ DoubleToString(real_value * 5), &options);
+ }
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();
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index e550e12..63cc5d1 100644
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -515,21 +515,21 @@
"enum": ["male", "female"]
},
"rate": {
- "type": "float",
+ "type": "number",
"optional": true,
"minimum": 0,
"maximum": 1,
"description": "Speaking speed between 0 and 1 inclusive, with 0 being slowest and 1 being fastest."
},
"pitch": {
- "type": "float",
+ "type": "number",
"optional": true,
"minimum": 0,
"maximum": 1,
"description": "Speaking pitch between 0 and 1 inclusive, with 0 being lowest and 1 being highest."
},
"volume": {
- "type": "float",
+ "type": "number",
"optional": true,
"minimum": 0,
"maximum": 1,