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

Side by Side Diff: chrome/browser/speech/tts_controller.cc

Issue 102263005: Automatically trigger installation of high-quality speech synthesis extension. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Change extension manifest to match Chrome OS Created 7 years 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
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/tts_controller.h" 5 #include "chrome/browser/speech/tts_controller.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/float_util.h" 10 #include "base/float_util.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // Select the matching voice, but if none was found, initialize an 159 // Select the matching voice, but if none was found, initialize an
160 // empty VoiceData with native = true, which will give the native 160 // empty VoiceData with native = true, which will give the native
161 // speech synthesizer a chance to try to synthesize the utterance 161 // speech synthesizer a chance to try to synthesize the utterance
162 // anyway. 162 // anyway.
163 VoiceData voice; 163 VoiceData voice;
164 if (index >= 0 && index < static_cast<int>(voices.size())) 164 if (index >= 0 && index < static_cast<int>(voices.size()))
165 voice = voices[index]; 165 voice = voices[index];
166 else 166 else
167 voice.native = true; 167 voice.native = true;
168 168
169 GetPlatformImpl()->WillSpeakUtteranceWithVoice(utterance, voice);
170
169 if (!voice.native) { 171 if (!voice.native) {
170 #if !defined(OS_ANDROID) 172 #if !defined(OS_ANDROID)
171 DCHECK(!voice.extension_id.empty()); 173 DCHECK(!voice.extension_id.empty());
172 current_utterance_ = utterance; 174 current_utterance_ = utterance;
173 utterance->set_extension_id(voice.extension_id); 175 utterance->set_extension_id(voice.extension_id);
174 ExtensionTtsEngineSpeak(utterance, voice); 176 ExtensionTtsEngineSpeak(utterance, voice);
175 bool sends_end_event = 177 bool sends_end_event =
176 voice.events.find(TTS_EVENT_END) != voice.events.end(); 178 voice.events.find(TTS_EVENT_END) != voice.events.end();
177 if (!sends_end_event) { 179 if (!sends_end_event) {
178 utterance->Finish(); 180 utterance->Finish();
179 delete utterance; 181 delete utterance;
180 current_utterance_ = NULL; 182 current_utterance_ = NULL;
181 SpeakNextUtterance(); 183 SpeakNextUtterance();
182 } 184 }
183 #endif 185 #endif
184 } else { 186 } else {
185 // It's possible for certain platforms to send start events immediately 187 // It's possible for certain platforms to send start events immediately
186 // during |speak|. 188 // during |speak|.
187 current_utterance_ = utterance; 189 current_utterance_ = utterance;
188 GetPlatformImpl()->clear_error(); 190 GetPlatformImpl()->clear_error();
189 bool success = GetPlatformImpl()->Speak( 191 bool success = GetPlatformImpl()->Speak(
190 utterance->id(), 192 utterance->id(),
191 utterance->text(), 193 utterance->text(),
192 utterance->lang(), 194 utterance->lang(),
193 voice, 195 voice,
194 utterance->continuous_parameters()); 196 utterance->continuous_parameters());
195 if (!success) 197 if (!success)
196 current_utterance_ = NULL; 198 current_utterance_ = NULL;
197 199
198 // If the native voice wasn't able to process this speech, see if
199 // the browser has built-in TTS that isn't loaded yet.
200 if (!success &&
201 GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->profile())) {
202 utterance_queue_.push(utterance);
203 return;
204 }
205
206 if (!success) { 200 if (!success) {
207 utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex, 201 utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex,
208 GetPlatformImpl()->error()); 202 GetPlatformImpl()->error());
209 delete utterance; 203 delete utterance;
210 return; 204 return;
211 } 205 }
212 } 206 }
213 } 207 }
214 208
215 void TtsController::Stop() { 209 void TtsController::Stop() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 300
307 // Start speaking the next utterance in the queue. Keep trying in case 301 // Start speaking the next utterance in the queue. Keep trying in case
308 // one fails but there are still more in the queue to try. 302 // one fails but there are still more in the queue to try.
309 while (!utterance_queue_.empty() && !current_utterance_) { 303 while (!utterance_queue_.empty() && !current_utterance_) {
310 Utterance* utterance = utterance_queue_.front(); 304 Utterance* utterance = utterance_queue_.front();
311 utterance_queue_.pop(); 305 utterance_queue_.pop();
312 SpeakNow(utterance); 306 SpeakNow(utterance);
313 } 307 }
314 } 308 }
315 309
316 void TtsController::RetrySpeakingQueuedUtterances() {
317 if (current_utterance_ == NULL && !utterance_queue_.empty())
318 SpeakNextUtterance();
319 }
320
321 void TtsController::ClearUtteranceQueue(bool send_events) { 310 void TtsController::ClearUtteranceQueue(bool send_events) {
322 while (!utterance_queue_.empty()) { 311 while (!utterance_queue_.empty()) {
323 Utterance* utterance = utterance_queue_.front(); 312 Utterance* utterance = utterance_queue_.front();
324 utterance_queue_.pop(); 313 utterance_queue_.pop();
325 if (send_events) 314 if (send_events)
326 utterance->OnTtsEvent(TTS_EVENT_CANCELLED, kInvalidCharIndex, 315 utterance->OnTtsEvent(TTS_EVENT_CANCELLED, kInvalidCharIndex,
327 std::string()); 316 std::string());
328 else 317 else
329 utterance->Finish(); 318 utterance->Finish();
330 delete utterance; 319 delete utterance;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 402 }
414 403
415 void TtsController::AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) { 404 void TtsController::AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) {
416 voices_changed_delegates_.insert(delegate); 405 voices_changed_delegates_.insert(delegate);
417 } 406 }
418 407
419 void TtsController::RemoveVoicesChangedDelegate( 408 void TtsController::RemoveVoicesChangedDelegate(
420 VoicesChangedDelegate* delegate) { 409 VoicesChangedDelegate* delegate) {
421 voices_changed_delegates_.erase(delegate); 410 voices_changed_delegates_.erase(delegate);
422 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698