Skip to content

Commit

Permalink
Ignore bogus willSpeakWord callbacks from Mac speech synthesizer.
Browse files Browse the repository at this point in the history
The Mac willSpeakWord callback occasionally returns bogus offsets,
leading to an assertion failure later. Add some code to just ignore
the callback in that case.

BUG=602776

Review-Url: https://codereview.chromium.org/2363553006
Cr-Commit-Position: refs/heads/master@{#424450}
  • Loading branch information
minorninth authored and Commit bot committed Oct 11, 2016
1 parent 7f7c8cc commit 13741f1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions chrome/browser/speech/tts_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ void OnSpeechEvent(NSSpeechSynthesizer* sender,

if (event_type == TTS_EVENT_END)
char_index = utterance_.size();

TtsController* controller = TtsController::GetInstance();
controller->OnTtsEvent(
controller->OnTtsEvent(
utterance_id_, event_type, char_index, error_message);
last_char_index_ = char_index;
}
Expand Down Expand Up @@ -308,16 +309,26 @@ - (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
}

- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
willSpeakWord:(NSRange)character_range
willSpeakWord:(NSRange)word_range
ofString:(NSString*)string {
// Ignore bogus word_range. The Mac speech synthesizer is a bit
// buggy and occasionally returns a number way out of range.
if (word_range.location > [string length])
return;

ttsImplMac_->OnSpeechEvent(sender, TTS_EVENT_WORD,
character_range.location, "");
word_range.location, "");
}

- (void)speechSynthesizer:(NSSpeechSynthesizer*)sender
didEncounterErrorAtIndex:(NSUInteger)character_index
ofString:(NSString*)string
message:(NSString*)message {
// Ignore bogus character_index. The Mac speech synthesizer is a bit
// buggy and occasionally returns a number way out of range.
if (character_index > [string length])
return;

std::string message_utf8 = base::SysNSStringToUTF8(message);
ttsImplMac_->OnSpeechEvent(sender, TTS_EVENT_ERROR, character_index,
message_utf8);
Expand Down

0 comments on commit 13741f1

Please sign in to comment.