Bug 1254674 - Calling speak() on an empty utterance should not raise an error. r?eeejay draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 31 Mar 2016 16:26:59 +0900
changeset 346185 fc3149010305e18aee63ea6d5782e2abd56a695d
parent 345720 494289c72ba3997183e7b5beaca3e0447ecaf96d
child 517353 ab34e6865db6e3a9d3d9733a060a8c027fe75991
push id14272
push userm_kato@ga2.so-net.ne.jp
push dateThu, 31 Mar 2016 07:37:56 +0000
reviewerseeejay
bugs1254674
milestone48.0a1
Bug 1254674 - Calling speak() on an empty utterance should not raise an error. r?eeejay OSX's NSSpeechSynthesizer throws error when text is empty. So we dispatch start and end event manually when text is empty. MozReview-Commit-ID: 5tr8Xx1JP8J
dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm
--- a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm
+++ b/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm
@@ -364,16 +364,24 @@ OSXSpeechSynthesizerService::Speak(const
                                    float aPitch,
                                    nsISpeechTask* aTask)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   MOZ_ASSERT(StringBeginsWith(aUri, NS_LITERAL_STRING("urn:moz-tts:osx:")),
              "OSXSpeechSynthesizerService doesn't allow this voice URI");
 
+  if (aText.IsEmpty()) {
+    // NSSpeechSynthesizer throws error when text is empty.
+    // If so, we dispatch start and end event instead of error
+    aTask->DispatchStart();
+    aTask->DispatchEnd(0, 0);
+    return NS_OK;
+  }
+
   NSSpeechSynthesizer* synth = [[NSSpeechSynthesizer alloc] init];
   // strlen("urn:moz-tts:osx:") == 16
   NSString* identifier = nsCocoaUtils::ToNSString(Substring(aUri, 16));
   [synth setVoice:identifier];
 
   // default rate is 180-220
   [synth setObject:[NSNumber numberWithInt:aRate * 200]
          forProperty:NSSpeechRateProperty error:nil];