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

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

Issue 15012027: Android implementation of text-to-speech code for Web Speech Synthesis API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tts_multivoice
Patch Set: Fix clang error Created 7 years, 7 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 | « chrome/browser/speech/tts_controller.h ('k') | chrome/browser/speech/tts_message_filter.h » ('j') | 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/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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // empty VoiceData with native = true, which will give the native 149 // empty VoiceData with native = true, which will give the native
150 // speech synthesizer a chance to try to synthesize the utterance 150 // speech synthesizer a chance to try to synthesize the utterance
151 // anyway. 151 // anyway.
152 VoiceData voice; 152 VoiceData voice;
153 if (index >= 0 && index < static_cast<int>(voices.size())) 153 if (index >= 0 && index < static_cast<int>(voices.size()))
154 voice = voices[index]; 154 voice = voices[index];
155 else 155 else
156 voice.native = true; 156 voice.native = true;
157 157
158 if (!voice.native) { 158 if (!voice.native) {
159 #if !defined(OS_ANDROID)
159 DCHECK(!voice.extension_id.empty()); 160 DCHECK(!voice.extension_id.empty());
160 current_utterance_ = utterance; 161 current_utterance_ = utterance;
161 utterance->set_extension_id(voice.extension_id); 162 utterance->set_extension_id(voice.extension_id);
162 ExtensionTtsEngineSpeak(utterance, voice); 163 ExtensionTtsEngineSpeak(utterance, voice);
163 bool sends_end_event = 164 bool sends_end_event =
164 voice.events.find(TTS_EVENT_END) != voice.events.end(); 165 voice.events.find(TTS_EVENT_END) != voice.events.end();
165 if (!sends_end_event) { 166 if (!sends_end_event) {
166 utterance->Finish(); 167 utterance->Finish();
167 delete utterance; 168 delete utterance;
168 current_utterance_ = NULL; 169 current_utterance_ = NULL;
169 SpeakNextUtterance(); 170 SpeakNextUtterance();
170 } 171 }
172 #endif
171 } else { 173 } else {
172 GetPlatformImpl()->clear_error(); 174 GetPlatformImpl()->clear_error();
173 bool success = GetPlatformImpl()->Speak( 175 bool success = GetPlatformImpl()->Speak(
174 utterance->id(), 176 utterance->id(),
175 utterance->text(), 177 utterance->text(),
176 utterance->lang(), 178 utterance->lang(),
177 voice, 179 voice,
178 utterance->continuous_parameters()); 180 utterance->continuous_parameters());
179 181
180 // If the native voice wasn't able to process this speech, see if 182 // If the native voice wasn't able to process this speech, see if
181 // the browser has built-in TTS that isn't loaded yet. 183 // the browser has built-in TTS that isn't loaded yet.
182 if (!success && 184 if (!success &&
183 GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->profile())) { 185 GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->profile())) {
184 utterance_queue_.push(utterance); 186 utterance_queue_.push(utterance);
185 return; 187 return;
186 } 188 }
187 189
188 if (!success) { 190 if (!success) {
189 utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex, 191 utterance->OnTtsEvent(TTS_EVENT_ERROR, kInvalidCharIndex,
190 GetPlatformImpl()->error()); 192 GetPlatformImpl()->error());
191 delete utterance; 193 delete utterance;
192 return; 194 return;
193 } 195 }
194 current_utterance_ = utterance; 196 current_utterance_ = utterance;
195 } 197 }
196 } 198 }
197 199
198 void TtsController::Stop() { 200 void TtsController::Stop() {
199 if (current_utterance_ && !current_utterance_->extension_id().empty()) { 201 if (current_utterance_ && !current_utterance_->extension_id().empty()) {
202 #if !defined(OS_ANDROID)
200 ExtensionTtsEngineStop(current_utterance_); 203 ExtensionTtsEngineStop(current_utterance_);
204 #endif
201 } else { 205 } else {
202 GetPlatformImpl()->clear_error(); 206 GetPlatformImpl()->clear_error();
203 GetPlatformImpl()->StopSpeaking(); 207 GetPlatformImpl()->StopSpeaking();
204 } 208 }
205 209
206 if (current_utterance_) 210 if (current_utterance_)
207 current_utterance_->OnTtsEvent(TTS_EVENT_INTERRUPTED, kInvalidCharIndex, 211 current_utterance_->OnTtsEvent(TTS_EVENT_INTERRUPTED, kInvalidCharIndex,
208 std::string()); 212 std::string());
209 FinishCurrentUtterance(); 213 FinishCurrentUtterance();
210 ClearUtteranceQueue(true); // Send events. 214 ClearUtteranceQueue(true); // Send events.
(...skipping 12 matching lines...) Expand all
223 227
224 current_utterance_->OnTtsEvent(event_type, char_index, error_message); 228 current_utterance_->OnTtsEvent(event_type, char_index, error_message);
225 if (current_utterance_->finished()) { 229 if (current_utterance_->finished()) {
226 FinishCurrentUtterance(); 230 FinishCurrentUtterance();
227 SpeakNextUtterance(); 231 SpeakNextUtterance();
228 } 232 }
229 } 233 }
230 234
231 void TtsController::GetVoices(Profile* profile, 235 void TtsController::GetVoices(Profile* profile,
232 std::vector<VoiceData>* out_voices) { 236 std::vector<VoiceData>* out_voices) {
237 #if !defined(OS_ANDROID)
233 if (profile) 238 if (profile)
234 GetExtensionVoices(profile, out_voices); 239 GetExtensionVoices(profile, out_voices);
240 #endif
235 241
236 TtsPlatformImpl* platform_impl = GetPlatformImpl(); 242 TtsPlatformImpl* platform_impl = GetPlatformImpl();
237 if (platform_impl && platform_impl->PlatformImplAvailable()) 243 if (platform_impl && platform_impl->PlatformImplAvailable())
238 platform_impl->GetVoices(out_voices); 244 platform_impl->GetVoices(out_voices);
239 } 245 }
240 246
241 bool TtsController::IsSpeaking() { 247 bool TtsController::IsSpeaking() {
242 return current_utterance_ != NULL || GetPlatformImpl()->IsSpeaking(); 248 return current_utterance_ != NULL || GetPlatformImpl()->IsSpeaking();
243 } 249 }
244 250
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 continue; 352 continue;
347 } 353 }
348 354
349 return static_cast<int>(i); 355 return static_cast<int>(i);
350 } 356 }
351 } 357 }
352 358
353 return -1; 359 return -1;
354 } 360 }
355 361
362 void TtsController::VoicesChanged() {
363 for (std::set<VoicesChangedDelegate*>::iterator iter =
364 voices_changed_delegates_.begin();
365 iter != voices_changed_delegates_.end(); ++iter) {
366 (*iter)->OnVoicesChanged();
367 }
368 }
369
370 void TtsController::AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) {
371 voices_changed_delegates_.insert(delegate);
372 }
373
374 void TtsController::RemoveVoicesChangedDelegate(
375 VoicesChangedDelegate* delegate) {
376 voices_changed_delegates_.erase(delegate);
377 }
378
OLDNEW
« no previous file with comments | « chrome/browser/speech/tts_controller.h ('k') | chrome/browser/speech/tts_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698