1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright (c) 2010 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.
#include "chrome/browser/extensions/extension_tts_api.h"
#include <string>
#include "base/float_util.h"
#include "base/values.h"
namespace util = extension_tts_api_util;
namespace {
const char kCrosLibraryNotLoadedError[] =
"Cros shared library not loaded.";
};
bool ExtensionTtsSpeakFunction::RunImpl() {
std::string utterance;
std::string language;
std::string gender;
double rate = -1.0;
double pitch = -1.0;
double volume = -1.0;
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);
}
if (speak_options->HasKey(util::kGenderKey)) {
speak_options->GetString(util::kGenderKey, &gender);
}
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::kPitchKey, &pitch)) {
if (!base::IsFinite(pitch) || pitch < 0.0 || pitch > 1.0) {
pitch = -1.0;
}
}
if (util::ReadNumberByKey(speak_options, util::kVolumeKey, &volume)) {
if (!base::IsFinite(volume) || volume < 0.0 || volume > 1.0) {
volume = -1.0;
}
}
}
ExtensionTtsPlatformImpl* impl = ExtensionTtsPlatformImpl::GetInstance();
impl->clear_error();
return impl->Speak(utterance, language, gender, rate, pitch, volume);
}
bool ExtensionTtsStopSpeakingFunction::RunImpl() {
ExtensionTtsPlatformImpl* impl = ExtensionTtsPlatformImpl::GetInstance();
impl->clear_error();
return impl->StopSpeaking();
}
bool ExtensionTtsIsSpeakingFunction::RunImpl() {
ExtensionTtsPlatformImpl* impl = ExtensionTtsPlatformImpl::GetInstance();
impl->clear_error();
result_.reset(Value::CreateBooleanValue(impl->IsSpeaking()));
return true;
}
|