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/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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 GetPlatformImpl()->clear_error(); | 189 GetPlatformImpl()->clear_error(); |
190 bool success = GetPlatformImpl()->Speak( | 190 bool success = GetPlatformImpl()->Speak( |
191 utterance->id(), | 191 utterance->id(), |
192 utterance->text(), | 192 utterance->text(), |
193 utterance->lang(), | 193 utterance->lang(), |
194 voice, | 194 voice, |
195 utterance->continuous_parameters()); | 195 utterance->continuous_parameters()); |
196 if (!success) | 196 if (!success) |
197 current_utterance_ = NULL; | 197 current_utterance_ = NULL; |
198 | 198 |
| 199 // If the native voice wasn't able to process this speech, see if |
| 200 // the browser has built-in TTS that isn't loaded yet. |
| 201 if (!success && |
| 202 GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->profile())) { |
| 203 utterance_queue_.push(utterance); |
| 204 return; |
| 205 } |
| 206 |
199 if (!success) { | 207 if (!success) { |
200 utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex, | 208 utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex, |
201 GetPlatformImpl()->error()); | 209 GetPlatformImpl()->error()); |
202 delete utterance; | 210 delete utterance; |
203 return; | 211 return; |
204 } | 212 } |
205 } | 213 } |
206 } | 214 } |
207 | 215 |
208 void TtsController::Stop() { | 216 void TtsController::Stop() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 307 |
300 // Start speaking the next utterance in the queue. Keep trying in case | 308 // Start speaking the next utterance in the queue. Keep trying in case |
301 // one fails but there are still more in the queue to try. | 309 // one fails but there are still more in the queue to try. |
302 while (!utterance_queue_.empty() && !current_utterance_) { | 310 while (!utterance_queue_.empty() && !current_utterance_) { |
303 Utterance* utterance = utterance_queue_.front(); | 311 Utterance* utterance = utterance_queue_.front(); |
304 utterance_queue_.pop(); | 312 utterance_queue_.pop(); |
305 SpeakNow(utterance); | 313 SpeakNow(utterance); |
306 } | 314 } |
307 } | 315 } |
308 | 316 |
| 317 void TtsController::RetrySpeakingQueuedUtterances() { |
| 318 if (current_utterance_ == NULL && !utterance_queue_.empty()) |
| 319 SpeakNextUtterance(); |
| 320 } |
| 321 |
309 void TtsController::ClearUtteranceQueue(bool send_events) { | 322 void TtsController::ClearUtteranceQueue(bool send_events) { |
310 while (!utterance_queue_.empty()) { | 323 while (!utterance_queue_.empty()) { |
311 Utterance* utterance = utterance_queue_.front(); | 324 Utterance* utterance = utterance_queue_.front(); |
312 utterance_queue_.pop(); | 325 utterance_queue_.pop(); |
313 if (send_events) | 326 if (send_events) |
314 utterance->OnTtsEvent(TTS_EVENT_CANCELLED, kInvalidCharIndex, | 327 utterance->OnTtsEvent(TTS_EVENT_CANCELLED, kInvalidCharIndex, |
315 std::string()); | 328 std::string()); |
316 else | 329 else |
317 utterance->Finish(); | 330 utterance->Finish(); |
318 delete utterance; | 331 delete utterance; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 414 } |
402 | 415 |
403 void TtsController::AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) { | 416 void TtsController::AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) { |
404 voices_changed_delegates_.insert(delegate); | 417 voices_changed_delegates_.insert(delegate); |
405 } | 418 } |
406 | 419 |
407 void TtsController::RemoveVoicesChangedDelegate( | 420 void TtsController::RemoveVoicesChangedDelegate( |
408 VoicesChangedDelegate* delegate) { | 421 VoicesChangedDelegate* delegate) { |
409 voices_changed_delegates_.erase(delegate); | 422 voices_changed_delegates_.erase(delegate); |
410 } | 423 } |
OLD | NEW |