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
--- 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];