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

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

Powered by Google App Engine
This is Rietveld 408576698