Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: chrome/browser/speech/extension_api/tts_engine_extension_api.cc

Issue 969913002: Fix rate, pitch, and volume from web speech synthesis API to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 voice.event_types.end()) { 131 voice.event_types.end()) {
132 result_voice.events.insert(TTS_EVENT_CANCELLED); 132 result_voice.events.insert(TTS_EVENT_CANCELLED);
133 result_voice.events.insert(TTS_EVENT_INTERRUPTED); 133 result_voice.events.insert(TTS_EVENT_INTERRUPTED);
134 } 134 }
135 } 135 }
136 } 136 }
137 } 137 }
138 138
139 void TtsExtensionEngine::Speak(Utterance* utterance, 139 void TtsExtensionEngine::Speak(Utterance* utterance,
140 const VoiceData& voice) { 140 const VoiceData& voice) {
141 LOG(ERROR) << "TtsExtensionEngine::Speak";
David Tseng 2015/03/16 17:56:50 Remove
142 {
143 std::string json;
144 base::JSONWriter::Write(utterance->options(), &json);
145 LOG(ERROR) << "Options: " << json;
David Tseng 2015/03/16 17:56:50 Remove
146 }
147
141 // See if the engine supports the "end" event; if so, we can keep the 148 // See if the engine supports the "end" event; if so, we can keep the
142 // utterance around and track it. If not, we're finished with this 149 // utterance around and track it. If not, we're finished with this
143 // utterance now. 150 // utterance now.
144 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end(); 151 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end();
145 152
146 scoped_ptr<base::ListValue> args(new base::ListValue()); 153 scoped_ptr<base::ListValue> args(new base::ListValue());
147 args->AppendString(utterance->text()); 154 args->AppendString(utterance->text());
148 155
149 // Pass through most options to the speech engine, but remove some 156 // Pass through most options to the speech engine, but remove some
150 // that are handled internally. 157 // that are handled internally.
151 scoped_ptr<base::DictionaryValue> options(static_cast<base::DictionaryValue*>( 158 scoped_ptr<base::DictionaryValue> options(static_cast<base::DictionaryValue*>(
152 utterance->options()->DeepCopy())); 159 utterance->options()->DeepCopy()));
153 if (options->HasKey(constants::kRequiredEventTypesKey)) 160 if (options->HasKey(constants::kRequiredEventTypesKey))
154 options->Remove(constants::kRequiredEventTypesKey, NULL); 161 options->Remove(constants::kRequiredEventTypesKey, NULL);
155 if (options->HasKey(constants::kDesiredEventTypesKey)) 162 if (options->HasKey(constants::kDesiredEventTypesKey))
156 options->Remove(constants::kDesiredEventTypesKey, NULL); 163 options->Remove(constants::kDesiredEventTypesKey, NULL);
157 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) 164 if (sends_end_event && options->HasKey(constants::kEnqueueKey))
158 options->Remove(constants::kEnqueueKey, NULL); 165 options->Remove(constants::kEnqueueKey, NULL);
159 if (options->HasKey(constants::kSrcIdKey)) 166 if (options->HasKey(constants::kSrcIdKey))
160 options->Remove(constants::kSrcIdKey, NULL); 167 options->Remove(constants::kSrcIdKey, NULL);
161 if (options->HasKey(constants::kIsFinalEventKey)) 168 if (options->HasKey(constants::kIsFinalEventKey))
162 options->Remove(constants::kIsFinalEventKey, NULL); 169 options->Remove(constants::kIsFinalEventKey, NULL);
163 if (options->HasKey(constants::kOnEventKey)) 170 if (options->HasKey(constants::kOnEventKey))
164 options->Remove(constants::kOnEventKey, NULL); 171 options->Remove(constants::kOnEventKey, NULL);
165 172
173 // Get the volume, pitch, and rate, but only if they weren't already in
174 // the options. TODO(dmazzoni): these shouldn't be redundant.
175 // http://crbug.com/463264
176 if (!options->HasKey(constants::kRateKey)) {
177 options->SetDouble(constants::kRateKey,
178 utterance->continuous_parameters().rate);
179 }
180 if (!options->HasKey(constants::kPitchKey)) {
181 options->SetDouble(constants::kPitchKey,
182 utterance->continuous_parameters().pitch);
183 }
184 if (!options->HasKey(constants::kVolumeKey)) {
185 options->SetDouble(constants::kVolumeKey,
186 utterance->continuous_parameters().volume);
187 }
188
166 // Add the voice name and language to the options if they're not 189 // 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 190 // already there, since they might have been picked by the TTS controller
168 // rather than directly by the client that requested the speech. 191 // rather than directly by the client that requested the speech.
169 if (!options->HasKey(constants::kVoiceNameKey)) 192 if (!options->HasKey(constants::kVoiceNameKey))
170 options->SetString(constants::kVoiceNameKey, voice.name); 193 options->SetString(constants::kVoiceNameKey, voice.name);
171 if (!options->HasKey(constants::kLangKey)) 194 if (!options->HasKey(constants::kLangKey))
172 options->SetString(constants::kLangKey, voice.lang); 195 options->SetString(constants::kLangKey, voice.lang);
173 196
174 args->Append(options.release()); 197 args->Append(options.release());
175 args->AppendInteger(utterance->id()); 198 args->AppendInteger(utterance->id());
176 199
200 std::string json;
201 base::JSONWriter::Write(args.get(), &json);
202 LOG(ERROR) << "To Extension: " << json;
David Tseng 2015/03/16 17:56:50 Remove
203
177 scoped_ptr<extensions::Event> event(new extensions::Event( 204 scoped_ptr<extensions::Event> event(new extensions::Event(
178 tts_engine_events::kOnSpeak, args.Pass())); 205 tts_engine_events::kOnSpeak, args.Pass()));
179 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); 206 Profile* profile = Profile::FromBrowserContext(utterance->browser_context());
180 event->restrict_to_browser_context = profile; 207 event->restrict_to_browser_context = profile;
181 EventRouter::Get(profile) 208 EventRouter::Get(profile)
182 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); 209 ->DispatchEventToExtension(utterance->extension_id(), event.Pass());
183 } 210 }
184 211
185 void TtsExtensionEngine::Stop(Utterance* utterance) { 212 void TtsExtensionEngine::Stop(Utterance* utterance) {
186 scoped_ptr<base::ListValue> args(new base::ListValue()); 213 scoped_ptr<base::ListValue> args(new base::ListValue());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); 329 utterance_id, TTS_EVENT_PAUSE, char_index, std::string());
303 } else if (event_type == constants::kEventTypeResume) { 330 } else if (event_type == constants::kEventTypeResume) {
304 controller->OnTtsEvent( 331 controller->OnTtsEvent(
305 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); 332 utterance_id, TTS_EVENT_RESUME, char_index, std::string());
306 } else { 333 } else {
307 EXTENSION_FUNCTION_VALIDATE(false); 334 EXTENSION_FUNCTION_VALIDATE(false);
308 } 335 }
309 336
310 return true; 337 return true;
311 } 338 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698