问题
Right now, my app implements AVSpeechSynthesizer
to read out instructions for each screen. The app also takes into consideration when Voiceover accessibility feature is enabled.
The problem I'm facing now is that the text to speech feature overlaps with the voiceover feature. Is there a solution to detect that when a user navigates to another element on the screen, TTS stops speaking, or when TTS is speaking, voiceover doesn't speak until TTS finishes (the former is preferred though).
The current development is on iOS 8, using Swift.
回答1:
OPTION 1
You could listen for when new elements are focused by observing UIAccessibilityElementFocusedNotification
notifications
[[NSNotificationCenter defaultCenter] addObserver:yourTTSManager
selector:@selector(interruptTTSFunction:)
name:UIAccessibilityElementFocusedNotification
object:nil];
and interrupt your custom speech synthesis announcements when they are received.
Pros: Gives the VoiceOver user a lot of control.
Cons: You don't know when VoiceOver is done reading off the newly focused control, so you can't use this to interrupt and restart announcements.
OPTION 2
You can tell VoiceOver to pause and restart by posting
UIAccessibilityPostNotification(UIAccessibilityPauseAssistiveTechnologyNotification, nil);
before your announcement and
UIAccessibilityPostNotification(UIAccessibilityResumeAssistiveTechnologyNotification, nil);
after it is complete.
Pros: Your announcement will get read off in it's entirety.
Cons: You take control out of the users hands when you pause VoiceOver.
RECOMENDATION
If your announcements are short, pausing and resuming the AT isn't a terrible solution. Otherwise, I would recommend allowing VoiceOver users to interrupt/cancel your announcements by listening for UIAccessibilityElementFocusedNotification
events, and canceling any active announcements when they are received.
来源:https://stackoverflow.com/questions/32943355/how-to-stop-text-to-speech-when-voiceover-is-speaking-or-vice-versa-in-swift