|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "nsILocaleService.h" |
|
8 #include "nsISpeechService.h" |
|
9 #include "nsServiceManagerUtils.h" |
|
10 |
|
11 #include "SpeechSynthesisUtterance.h" |
|
12 #include "SpeechSynthesisVoice.h" |
|
13 #include "nsSynthVoiceRegistry.h" |
|
14 #include "nsSpeechTask.h" |
|
15 |
|
16 #include "nsString.h" |
|
17 #include "mozilla/StaticPtr.h" |
|
18 #include "mozilla/dom/ContentChild.h" |
|
19 #include "mozilla/dom/ContentParent.h" |
|
20 #include "mozilla/unused.h" |
|
21 |
|
22 #include "SpeechSynthesisChild.h" |
|
23 #include "SpeechSynthesisParent.h" |
|
24 |
|
25 #undef LOG |
|
26 #ifdef PR_LOGGING |
|
27 extern PRLogModuleInfo* GetSpeechSynthLog(); |
|
28 #define LOG(type, msg) PR_LOG(GetSpeechSynthLog(), type, msg) |
|
29 #else |
|
30 #define LOG(type, msg) |
|
31 #endif |
|
32 |
|
33 namespace { |
|
34 |
|
35 void |
|
36 GetAllSpeechSynthActors(InfallibleTArray<mozilla::dom::SpeechSynthesisParent*>& aActors) |
|
37 { |
|
38 MOZ_ASSERT(NS_IsMainThread()); |
|
39 MOZ_ASSERT(aActors.IsEmpty()); |
|
40 |
|
41 nsAutoTArray<mozilla::dom::ContentParent*, 20> contentActors; |
|
42 mozilla::dom::ContentParent::GetAll(contentActors); |
|
43 |
|
44 for (uint32_t contentIndex = 0; |
|
45 contentIndex < contentActors.Length(); |
|
46 ++contentIndex) { |
|
47 MOZ_ASSERT(contentActors[contentIndex]); |
|
48 |
|
49 AutoInfallibleTArray<mozilla::dom::PSpeechSynthesisParent*, 5> speechsynthActors; |
|
50 contentActors[contentIndex]->ManagedPSpeechSynthesisParent(speechsynthActors); |
|
51 |
|
52 for (uint32_t speechsynthIndex = 0; |
|
53 speechsynthIndex < speechsynthActors.Length(); |
|
54 ++speechsynthIndex) { |
|
55 MOZ_ASSERT(speechsynthActors[speechsynthIndex]); |
|
56 |
|
57 mozilla::dom::SpeechSynthesisParent* actor = |
|
58 static_cast<mozilla::dom::SpeechSynthesisParent*>(speechsynthActors[speechsynthIndex]); |
|
59 aActors.AppendElement(actor); |
|
60 } |
|
61 } |
|
62 } |
|
63 } |
|
64 |
|
65 namespace mozilla { |
|
66 namespace dom { |
|
67 |
|
68 // VoiceData |
|
69 |
|
70 class VoiceData MOZ_FINAL |
|
71 { |
|
72 private: |
|
73 // Private destructor, to discourage deletion outside of Release(): |
|
74 ~VoiceData() {} |
|
75 |
|
76 public: |
|
77 VoiceData(nsISpeechService* aService, const nsAString& aUri, |
|
78 const nsAString& aName, const nsAString& aLang, bool aIsLocal) |
|
79 : mService(aService) |
|
80 , mUri(aUri) |
|
81 , mName(aName) |
|
82 , mLang(aLang) |
|
83 , mIsLocal(aIsLocal) {} |
|
84 |
|
85 NS_INLINE_DECL_REFCOUNTING(VoiceData) |
|
86 |
|
87 nsCOMPtr<nsISpeechService> mService; |
|
88 |
|
89 nsString mUri; |
|
90 |
|
91 nsString mName; |
|
92 |
|
93 nsString mLang; |
|
94 |
|
95 bool mIsLocal; |
|
96 }; |
|
97 |
|
98 // nsSynthVoiceRegistry |
|
99 |
|
100 static StaticRefPtr<nsSynthVoiceRegistry> gSynthVoiceRegistry; |
|
101 |
|
102 NS_IMPL_ISUPPORTS(nsSynthVoiceRegistry, nsISynthVoiceRegistry) |
|
103 |
|
104 nsSynthVoiceRegistry::nsSynthVoiceRegistry() |
|
105 : mSpeechSynthChild(nullptr) |
|
106 { |
|
107 if (XRE_GetProcessType() == GeckoProcessType_Content) { |
|
108 |
|
109 mSpeechSynthChild = new SpeechSynthesisChild(); |
|
110 ContentChild::GetSingleton()->SendPSpeechSynthesisConstructor(mSpeechSynthChild); |
|
111 |
|
112 InfallibleTArray<RemoteVoice> voices; |
|
113 InfallibleTArray<nsString> defaults; |
|
114 |
|
115 mSpeechSynthChild->SendReadVoiceList(&voices, &defaults); |
|
116 |
|
117 for (uint32_t i = 0; i < voices.Length(); ++i) { |
|
118 RemoteVoice voice = voices[i]; |
|
119 AddVoiceImpl(nullptr, voice.voiceURI(), |
|
120 voice.name(), voice.lang(), |
|
121 voice.localService()); |
|
122 } |
|
123 |
|
124 for (uint32_t i = 0; i < defaults.Length(); ++i) { |
|
125 SetDefaultVoice(defaults[i], true); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 nsSynthVoiceRegistry::~nsSynthVoiceRegistry() |
|
131 { |
|
132 LOG(PR_LOG_DEBUG, ("~nsSynthVoiceRegistry")); |
|
133 |
|
134 // mSpeechSynthChild's lifecycle is managed by the Content protocol. |
|
135 mSpeechSynthChild = nullptr; |
|
136 |
|
137 mUriVoiceMap.Clear(); |
|
138 } |
|
139 |
|
140 nsSynthVoiceRegistry* |
|
141 nsSynthVoiceRegistry::GetInstance() |
|
142 { |
|
143 MOZ_ASSERT(NS_IsMainThread()); |
|
144 |
|
145 if (!gSynthVoiceRegistry) { |
|
146 gSynthVoiceRegistry = new nsSynthVoiceRegistry(); |
|
147 } |
|
148 |
|
149 return gSynthVoiceRegistry; |
|
150 } |
|
151 |
|
152 already_AddRefed<nsSynthVoiceRegistry> |
|
153 nsSynthVoiceRegistry::GetInstanceForService() |
|
154 { |
|
155 nsRefPtr<nsSynthVoiceRegistry> registry = GetInstance(); |
|
156 |
|
157 return registry.forget(); |
|
158 } |
|
159 |
|
160 void |
|
161 nsSynthVoiceRegistry::Shutdown() |
|
162 { |
|
163 LOG(PR_LOG_DEBUG, ("[%s] nsSynthVoiceRegistry::Shutdown()", |
|
164 (XRE_GetProcessType() == GeckoProcessType_Content) ? "Content" : "Default")); |
|
165 gSynthVoiceRegistry = nullptr; |
|
166 } |
|
167 |
|
168 void |
|
169 nsSynthVoiceRegistry::SendVoices(InfallibleTArray<RemoteVoice>* aVoices, |
|
170 InfallibleTArray<nsString>* aDefaults) |
|
171 { |
|
172 for (uint32_t i=0; i < mVoices.Length(); ++i) { |
|
173 nsRefPtr<VoiceData> voice = mVoices[i]; |
|
174 |
|
175 aVoices->AppendElement(RemoteVoice(voice->mUri, voice->mName, voice->mLang, |
|
176 voice->mIsLocal)); |
|
177 } |
|
178 |
|
179 for (uint32_t i=0; i < mDefaultVoices.Length(); ++i) { |
|
180 aDefaults->AppendElement(mDefaultVoices[i]->mUri); |
|
181 } |
|
182 } |
|
183 |
|
184 void |
|
185 nsSynthVoiceRegistry::RecvRemoveVoice(const nsAString& aUri) |
|
186 { |
|
187 // If we dont have a local instance of the registry yet, we will recieve current |
|
188 // voices at contruction time. |
|
189 if(!gSynthVoiceRegistry) { |
|
190 return; |
|
191 } |
|
192 |
|
193 gSynthVoiceRegistry->RemoveVoice(nullptr, aUri); |
|
194 } |
|
195 |
|
196 void |
|
197 nsSynthVoiceRegistry::RecvAddVoice(const RemoteVoice& aVoice) |
|
198 { |
|
199 // If we dont have a local instance of the registry yet, we will recieve current |
|
200 // voices at contruction time. |
|
201 if(!gSynthVoiceRegistry) { |
|
202 return; |
|
203 } |
|
204 |
|
205 gSynthVoiceRegistry->AddVoiceImpl(nullptr, aVoice.voiceURI(), |
|
206 aVoice.name(), aVoice.lang(), |
|
207 aVoice.localService()); |
|
208 } |
|
209 |
|
210 void |
|
211 nsSynthVoiceRegistry::RecvSetDefaultVoice(const nsAString& aUri, bool aIsDefault) |
|
212 { |
|
213 // If we dont have a local instance of the registry yet, we will recieve current |
|
214 // voices at contruction time. |
|
215 if(!gSynthVoiceRegistry) { |
|
216 return; |
|
217 } |
|
218 |
|
219 gSynthVoiceRegistry->SetDefaultVoice(aUri, aIsDefault); |
|
220 } |
|
221 |
|
222 NS_IMETHODIMP |
|
223 nsSynthVoiceRegistry::AddVoice(nsISpeechService* aService, |
|
224 const nsAString& aUri, |
|
225 const nsAString& aName, |
|
226 const nsAString& aLang, |
|
227 bool aLocalService) |
|
228 { |
|
229 LOG(PR_LOG_DEBUG, |
|
230 ("nsSynthVoiceRegistry::AddVoice uri='%s' name='%s' lang='%s' local=%s", |
|
231 NS_ConvertUTF16toUTF8(aUri).get(), NS_ConvertUTF16toUTF8(aName).get(), |
|
232 NS_ConvertUTF16toUTF8(aLang).get(), |
|
233 aLocalService ? "true" : "false")); |
|
234 |
|
235 NS_ENSURE_FALSE(XRE_GetProcessType() == GeckoProcessType_Content, |
|
236 NS_ERROR_NOT_AVAILABLE); |
|
237 |
|
238 return AddVoiceImpl(aService, aUri, aName, aLang, |
|
239 aLocalService); |
|
240 } |
|
241 |
|
242 NS_IMETHODIMP |
|
243 nsSynthVoiceRegistry::RemoveVoice(nsISpeechService* aService, |
|
244 const nsAString& aUri) |
|
245 { |
|
246 LOG(PR_LOG_DEBUG, |
|
247 ("nsSynthVoiceRegistry::RemoveVoice uri='%s' (%s)", |
|
248 NS_ConvertUTF16toUTF8(aUri).get(), |
|
249 (XRE_GetProcessType() == GeckoProcessType_Content) ? "child" : "parent")); |
|
250 |
|
251 bool found = false; |
|
252 VoiceData* retval = mUriVoiceMap.GetWeak(aUri, &found); |
|
253 |
|
254 NS_ENSURE_TRUE(found, NS_ERROR_NOT_AVAILABLE); |
|
255 NS_ENSURE_TRUE(aService == retval->mService, NS_ERROR_INVALID_ARG); |
|
256 |
|
257 mVoices.RemoveElement(retval); |
|
258 mDefaultVoices.RemoveElement(retval); |
|
259 mUriVoiceMap.Remove(aUri); |
|
260 |
|
261 nsTArray<SpeechSynthesisParent*> ssplist; |
|
262 GetAllSpeechSynthActors(ssplist); |
|
263 |
|
264 for (uint32_t i = 0; i < ssplist.Length(); ++i) |
|
265 unused << ssplist[i]->SendVoiceRemoved(nsString(aUri)); |
|
266 |
|
267 return NS_OK; |
|
268 } |
|
269 |
|
270 NS_IMETHODIMP |
|
271 nsSynthVoiceRegistry::SetDefaultVoice(const nsAString& aUri, |
|
272 bool aIsDefault) |
|
273 { |
|
274 bool found = false; |
|
275 VoiceData* retval = mUriVoiceMap.GetWeak(aUri, &found); |
|
276 NS_ENSURE_TRUE(found, NS_ERROR_NOT_AVAILABLE); |
|
277 |
|
278 mDefaultVoices.RemoveElement(retval); |
|
279 |
|
280 LOG(PR_LOG_DEBUG, ("nsSynthVoiceRegistry::SetDefaultVoice %s %s", |
|
281 NS_ConvertUTF16toUTF8(aUri).get(), |
|
282 aIsDefault ? "true" : "false")); |
|
283 |
|
284 if (aIsDefault) { |
|
285 mDefaultVoices.AppendElement(retval); |
|
286 } |
|
287 |
|
288 if (XRE_GetProcessType() == GeckoProcessType_Default) { |
|
289 nsTArray<SpeechSynthesisParent*> ssplist; |
|
290 GetAllSpeechSynthActors(ssplist); |
|
291 |
|
292 for (uint32_t i = 0; i < ssplist.Length(); ++i) { |
|
293 unused << ssplist[i]->SendSetDefaultVoice(nsString(aUri), aIsDefault); |
|
294 } |
|
295 } |
|
296 |
|
297 return NS_OK; |
|
298 } |
|
299 |
|
300 NS_IMETHODIMP |
|
301 nsSynthVoiceRegistry::GetVoiceCount(uint32_t* aRetval) |
|
302 { |
|
303 *aRetval = mVoices.Length(); |
|
304 |
|
305 return NS_OK; |
|
306 } |
|
307 |
|
308 NS_IMETHODIMP |
|
309 nsSynthVoiceRegistry::GetVoice(uint32_t aIndex, nsAString& aRetval) |
|
310 { |
|
311 NS_ENSURE_TRUE(aIndex < mVoices.Length(), NS_ERROR_INVALID_ARG); |
|
312 |
|
313 aRetval = mVoices[aIndex]->mUri; |
|
314 |
|
315 return NS_OK; |
|
316 } |
|
317 |
|
318 NS_IMETHODIMP |
|
319 nsSynthVoiceRegistry::IsDefaultVoice(const nsAString& aUri, bool* aRetval) |
|
320 { |
|
321 bool found; |
|
322 VoiceData* voice = mUriVoiceMap.GetWeak(aUri, &found); |
|
323 NS_ENSURE_TRUE(found, NS_ERROR_NOT_AVAILABLE); |
|
324 |
|
325 for (int32_t i = mDefaultVoices.Length(); i > 0; ) { |
|
326 VoiceData* defaultVoice = mDefaultVoices[--i]; |
|
327 |
|
328 if (voice->mLang.Equals(defaultVoice->mLang)) { |
|
329 *aRetval = voice == defaultVoice; |
|
330 return NS_OK; |
|
331 } |
|
332 } |
|
333 |
|
334 *aRetval = false; |
|
335 return NS_OK; |
|
336 } |
|
337 |
|
338 NS_IMETHODIMP |
|
339 nsSynthVoiceRegistry::IsLocalVoice(const nsAString& aUri, bool* aRetval) |
|
340 { |
|
341 bool found; |
|
342 VoiceData* voice = mUriVoiceMap.GetWeak(aUri, &found); |
|
343 NS_ENSURE_TRUE(found, NS_ERROR_NOT_AVAILABLE); |
|
344 |
|
345 *aRetval = voice->mIsLocal; |
|
346 return NS_OK; |
|
347 } |
|
348 |
|
349 NS_IMETHODIMP |
|
350 nsSynthVoiceRegistry::GetVoiceLang(const nsAString& aUri, nsAString& aRetval) |
|
351 { |
|
352 bool found; |
|
353 VoiceData* voice = mUriVoiceMap.GetWeak(aUri, &found); |
|
354 NS_ENSURE_TRUE(found, NS_ERROR_NOT_AVAILABLE); |
|
355 |
|
356 aRetval = voice->mLang; |
|
357 return NS_OK; |
|
358 } |
|
359 |
|
360 NS_IMETHODIMP |
|
361 nsSynthVoiceRegistry::GetVoiceName(const nsAString& aUri, nsAString& aRetval) |
|
362 { |
|
363 bool found; |
|
364 VoiceData* voice = mUriVoiceMap.GetWeak(aUri, &found); |
|
365 NS_ENSURE_TRUE(found, NS_ERROR_NOT_AVAILABLE); |
|
366 |
|
367 aRetval = voice->mName; |
|
368 return NS_OK; |
|
369 } |
|
370 |
|
371 nsresult |
|
372 nsSynthVoiceRegistry::AddVoiceImpl(nsISpeechService* aService, |
|
373 const nsAString& aUri, |
|
374 const nsAString& aName, |
|
375 const nsAString& aLang, |
|
376 bool aLocalService) |
|
377 { |
|
378 bool found = false; |
|
379 mUriVoiceMap.GetWeak(aUri, &found); |
|
380 NS_ENSURE_FALSE(found, NS_ERROR_INVALID_ARG); |
|
381 |
|
382 nsRefPtr<VoiceData> voice = new VoiceData(aService, aUri, aName, aLang, |
|
383 aLocalService); |
|
384 |
|
385 mVoices.AppendElement(voice); |
|
386 mUriVoiceMap.Put(aUri, voice); |
|
387 |
|
388 nsTArray<SpeechSynthesisParent*> ssplist; |
|
389 GetAllSpeechSynthActors(ssplist); |
|
390 |
|
391 if (!ssplist.IsEmpty()) { |
|
392 mozilla::dom::RemoteVoice ssvoice(nsString(aUri), |
|
393 nsString(aName), |
|
394 nsString(aLang), |
|
395 aLocalService); |
|
396 |
|
397 for (uint32_t i = 0; i < ssplist.Length(); ++i) { |
|
398 unused << ssplist[i]->SendVoiceAdded(ssvoice); |
|
399 } |
|
400 } |
|
401 |
|
402 return NS_OK; |
|
403 } |
|
404 |
|
405 bool |
|
406 nsSynthVoiceRegistry::FindVoiceByLang(const nsAString& aLang, |
|
407 VoiceData** aRetval) |
|
408 { |
|
409 nsAString::const_iterator dashPos, start, end; |
|
410 aLang.BeginReading(start); |
|
411 aLang.EndReading(end); |
|
412 |
|
413 while (true) { |
|
414 nsAutoString langPrefix(Substring(start, end)); |
|
415 |
|
416 for (int32_t i = mDefaultVoices.Length(); i > 0; ) { |
|
417 VoiceData* voice = mDefaultVoices[--i]; |
|
418 |
|
419 if (StringBeginsWith(voice->mLang, langPrefix)) { |
|
420 *aRetval = voice; |
|
421 return true; |
|
422 } |
|
423 } |
|
424 |
|
425 for (int32_t i = mVoices.Length(); i > 0; ) { |
|
426 VoiceData* voice = mVoices[--i]; |
|
427 |
|
428 if (StringBeginsWith(voice->mLang, langPrefix)) { |
|
429 *aRetval = voice; |
|
430 return true; |
|
431 } |
|
432 } |
|
433 |
|
434 dashPos = end; |
|
435 end = start; |
|
436 |
|
437 if (!RFindInReadable(NS_LITERAL_STRING("-"), end, dashPos)) { |
|
438 break; |
|
439 } |
|
440 } |
|
441 |
|
442 return false; |
|
443 } |
|
444 |
|
445 VoiceData* |
|
446 nsSynthVoiceRegistry::FindBestMatch(const nsAString& aUri, |
|
447 const nsAString& aLang) |
|
448 { |
|
449 if (mVoices.IsEmpty()) { |
|
450 return nullptr; |
|
451 } |
|
452 |
|
453 bool found = false; |
|
454 VoiceData* retval = mUriVoiceMap.GetWeak(aUri, &found); |
|
455 |
|
456 if (found) { |
|
457 LOG(PR_LOG_DEBUG, ("nsSynthVoiceRegistry::FindBestMatch - Matched URI")); |
|
458 return retval; |
|
459 } |
|
460 |
|
461 // Try finding a match for given voice. |
|
462 if (!aLang.IsVoid() && !aLang.IsEmpty()) { |
|
463 if (FindVoiceByLang(aLang, &retval)) { |
|
464 LOG(PR_LOG_DEBUG, |
|
465 ("nsSynthVoiceRegistry::FindBestMatch - Matched language (%s ~= %s)", |
|
466 NS_ConvertUTF16toUTF8(aLang).get(), |
|
467 NS_ConvertUTF16toUTF8(retval->mLang).get())); |
|
468 |
|
469 return retval; |
|
470 } |
|
471 } |
|
472 |
|
473 // Try UI language. |
|
474 nsresult rv; |
|
475 nsCOMPtr<nsILocaleService> localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); |
|
476 NS_ENSURE_SUCCESS(rv, nullptr); |
|
477 |
|
478 nsAutoString uiLang; |
|
479 rv = localeService->GetLocaleComponentForUserAgent(uiLang); |
|
480 NS_ENSURE_SUCCESS(rv, nullptr); |
|
481 |
|
482 if (FindVoiceByLang(uiLang, &retval)) { |
|
483 LOG(PR_LOG_DEBUG, |
|
484 ("nsSynthVoiceRegistry::FindBestMatch - Matched UI language (%s ~= %s)", |
|
485 NS_ConvertUTF16toUTF8(uiLang).get(), |
|
486 NS_ConvertUTF16toUTF8(retval->mLang).get())); |
|
487 |
|
488 return retval; |
|
489 } |
|
490 |
|
491 // Try en-US, the language of locale "C" |
|
492 if (FindVoiceByLang(NS_LITERAL_STRING("en-US"), &retval)) { |
|
493 LOG(PR_LOG_DEBUG, |
|
494 ("nsSynthVoiceRegistry::FindBestMatch - Matched C locale language (en-US ~= %s)", |
|
495 NS_ConvertUTF16toUTF8(retval->mLang).get())); |
|
496 |
|
497 return retval; |
|
498 } |
|
499 |
|
500 // The top default voice is better than nothing... |
|
501 if (!mDefaultVoices.IsEmpty()) { |
|
502 return mDefaultVoices.LastElement(); |
|
503 } |
|
504 |
|
505 return nullptr; |
|
506 } |
|
507 |
|
508 already_AddRefed<nsSpeechTask> |
|
509 nsSynthVoiceRegistry::SpeakUtterance(SpeechSynthesisUtterance& aUtterance, |
|
510 const nsAString& aDocLang) |
|
511 { |
|
512 nsString lang = nsString(aUtterance.mLang.IsEmpty() ? aDocLang : aUtterance.mLang); |
|
513 nsAutoString uri; |
|
514 |
|
515 if (aUtterance.mVoice) { |
|
516 aUtterance.mVoice->GetVoiceURI(uri); |
|
517 } |
|
518 |
|
519 nsRefPtr<nsSpeechTask> task; |
|
520 if (XRE_GetProcessType() == GeckoProcessType_Content) { |
|
521 task = new SpeechTaskChild(&aUtterance); |
|
522 SpeechSynthesisRequestChild* actor = |
|
523 new SpeechSynthesisRequestChild(static_cast<SpeechTaskChild*>(task.get())); |
|
524 mSpeechSynthChild->SendPSpeechSynthesisRequestConstructor(actor, |
|
525 aUtterance.mText, |
|
526 lang, |
|
527 uri, |
|
528 aUtterance.Volume(), |
|
529 aUtterance.Rate(), |
|
530 aUtterance.Pitch()); |
|
531 } else { |
|
532 task = new nsSpeechTask(&aUtterance); |
|
533 Speak(aUtterance.mText, lang, uri, |
|
534 aUtterance.Rate(), aUtterance.Pitch(), task); |
|
535 } |
|
536 |
|
537 return task.forget(); |
|
538 } |
|
539 |
|
540 void |
|
541 nsSynthVoiceRegistry::Speak(const nsAString& aText, |
|
542 const nsAString& aLang, |
|
543 const nsAString& aUri, |
|
544 const float& aRate, |
|
545 const float& aPitch, |
|
546 nsSpeechTask* aTask) |
|
547 { |
|
548 LOG(PR_LOG_DEBUG, |
|
549 ("nsSynthVoiceRegistry::Speak text='%s' lang='%s' uri='%s' rate=%f pitch=%f", |
|
550 NS_ConvertUTF16toUTF8(aText).get(), NS_ConvertUTF16toUTF8(aLang).get(), |
|
551 NS_ConvertUTF16toUTF8(aUri).get(), aRate, aPitch)); |
|
552 |
|
553 VoiceData* voice = FindBestMatch(aUri, aLang); |
|
554 |
|
555 if (!voice) { |
|
556 NS_WARNING("No voices found."); |
|
557 aTask->DispatchError(0, 0); |
|
558 return; |
|
559 } |
|
560 |
|
561 LOG(PR_LOG_DEBUG, ("nsSynthVoiceRegistry::Speak - Using voice URI: %s", |
|
562 NS_ConvertUTF16toUTF8(voice->mUri).get())); |
|
563 |
|
564 SpeechServiceType serviceType; |
|
565 |
|
566 DebugOnly<nsresult> rv = voice->mService->GetServiceType(&serviceType); |
|
567 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get speech service type"); |
|
568 |
|
569 if (serviceType == nsISpeechService::SERVICETYPE_INDIRECT_AUDIO) { |
|
570 aTask->SetIndirectAudio(true); |
|
571 } |
|
572 |
|
573 voice->mService->Speak(aText, voice->mUri, aRate, aPitch, aTask); |
|
574 } |
|
575 |
|
576 } // namespace dom |
|
577 } // namespace mozilla |