OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" | 5 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 options->Remove(constants::kDesiredEventTypesKey, NULL); | 156 options->Remove(constants::kDesiredEventTypesKey, NULL); |
157 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) | 157 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) |
158 options->Remove(constants::kEnqueueKey, NULL); | 158 options->Remove(constants::kEnqueueKey, NULL); |
159 if (options->HasKey(constants::kSrcIdKey)) | 159 if (options->HasKey(constants::kSrcIdKey)) |
160 options->Remove(constants::kSrcIdKey, NULL); | 160 options->Remove(constants::kSrcIdKey, NULL); |
161 if (options->HasKey(constants::kIsFinalEventKey)) | 161 if (options->HasKey(constants::kIsFinalEventKey)) |
162 options->Remove(constants::kIsFinalEventKey, NULL); | 162 options->Remove(constants::kIsFinalEventKey, NULL); |
163 if (options->HasKey(constants::kOnEventKey)) | 163 if (options->HasKey(constants::kOnEventKey)) |
164 options->Remove(constants::kOnEventKey, NULL); | 164 options->Remove(constants::kOnEventKey, NULL); |
165 | 165 |
| 166 // Get the volume, pitch, and rate, but only if they weren't already in |
| 167 // the options. TODO(dmazzoni): these shouldn't be redundant. |
| 168 // http://crbug.com/463264 |
| 169 if (!options->HasKey(constants::kRateKey)) { |
| 170 options->SetDouble(constants::kRateKey, |
| 171 utterance->continuous_parameters().rate); |
| 172 } |
| 173 if (!options->HasKey(constants::kPitchKey)) { |
| 174 options->SetDouble(constants::kPitchKey, |
| 175 utterance->continuous_parameters().pitch); |
| 176 } |
| 177 if (!options->HasKey(constants::kVolumeKey)) { |
| 178 options->SetDouble(constants::kVolumeKey, |
| 179 utterance->continuous_parameters().volume); |
| 180 } |
| 181 |
166 // Add the voice name and language to the options if they're not | 182 // Add the voice name and language to the options if they're not |
167 // already there, since they might have been picked by the TTS controller | 183 // already there, since they might have been picked by the TTS controller |
168 // rather than directly by the client that requested the speech. | 184 // rather than directly by the client that requested the speech. |
169 if (!options->HasKey(constants::kVoiceNameKey)) | 185 if (!options->HasKey(constants::kVoiceNameKey)) |
170 options->SetString(constants::kVoiceNameKey, voice.name); | 186 options->SetString(constants::kVoiceNameKey, voice.name); |
171 if (!options->HasKey(constants::kLangKey)) | 187 if (!options->HasKey(constants::kLangKey)) |
172 options->SetString(constants::kLangKey, voice.lang); | 188 options->SetString(constants::kLangKey, voice.lang); |
173 | 189 |
174 args->Append(options.release()); | 190 args->Append(options.release()); |
175 args->AppendInteger(utterance->id()); | 191 args->AppendInteger(utterance->id()); |
176 | 192 |
| 193 std::string json; |
| 194 base::JSONWriter::Write(args.get(), &json); |
| 195 |
177 scoped_ptr<extensions::Event> event(new extensions::Event( | 196 scoped_ptr<extensions::Event> event(new extensions::Event( |
178 tts_engine_events::kOnSpeak, args.Pass())); | 197 tts_engine_events::kOnSpeak, args.Pass())); |
179 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); | 198 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); |
180 event->restrict_to_browser_context = profile; | 199 event->restrict_to_browser_context = profile; |
181 EventRouter::Get(profile) | 200 EventRouter::Get(profile) |
182 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); | 201 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); |
183 } | 202 } |
184 | 203 |
185 void TtsExtensionEngine::Stop(Utterance* utterance) { | 204 void TtsExtensionEngine::Stop(Utterance* utterance) { |
186 scoped_ptr<base::ListValue> args(new base::ListValue()); | 205 scoped_ptr<base::ListValue> args(new base::ListValue()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); | 321 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); |
303 } else if (event_type == constants::kEventTypeResume) { | 322 } else if (event_type == constants::kEventTypeResume) { |
304 controller->OnTtsEvent( | 323 controller->OnTtsEvent( |
305 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); | 324 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); |
306 } else { | 325 } else { |
307 EXTENSION_FUNCTION_VALIDATE(false); | 326 EXTENSION_FUNCTION_VALIDATE(false); |
308 } | 327 } |
309 | 328 |
310 return true; | 329 return true; |
311 } | 330 } |
OLD | NEW |