6

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.

Cherie CH.
  • 171
  • 2
  • 8

1 Answers1

5

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.

MobA11y
  • 18,425
  • 3
  • 49
  • 76
  • Hi Chris! Thanks for your suggestion! However, I can't seem to find the Notification method that you're using. The only available ones to use are from this [link](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAccessibilityFocus_Protocol/index.html#//apple_ref/occ/instm/NSObject/accessibilityElementDidLoseFocus). I have tried overriding the `accessibilityElementDidLoseFocus()` and `accessibilityElementDidBecomeFocused()` methods as well but doesn't seem to be of help when I navigate to the next element in VoiceOver accessibility mode. Any ideas on this? – Cherie CH. Oct 23 '15 at 16:44
  • It's not a method at all. You have to register to listen for notifications. If you don't know what these are you should read up about them, as the answer to that is outside of the scope of this question: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Notifications/Articles/Registering.html – MobA11y Oct 24 '15 at 23:37
  • Thanks for the clarification Chris! As I'm still new to this, I would just like to clarify if `UIAccessibilityElementFocusedNotification` is available to use on iOS8? And if yes, do you mind sharing a link on how to go about carrying this out? (: – Cherie CH. Oct 25 '15 at 04:02
  • Here is a link to a blog post about posting notifications: http://www.deque.com/blog/dynamic-notifications/ Not all accessibility notifications can (or rather should) be posted, others are posted by iOS and in turn observed by the application. But, this isn't accessibility specific. Only the notification names are accessibility specific, the concept of posting and listening for notifications is identical across all iOS Framework APIs. I'd be happy to provide a deeper answer, but you should ask a different question, as this answer doesn't really belong under this question. – MobA11y Oct 26 '15 at 02:44
  • I added code snippets for how to do this in the answer, if you need more help PM me! – MobA11y Oct 26 '15 at 02:57
  • 3
    According to `UIAccessibilityConstants.h`: `Currently, these notifications only apply to Switch Control.` So you can' pause VoiceOver, which my testing confirms :( – Brenden Oct 27 '15 at 05:29
  • Option one is better anyway! – MobA11y Oct 27 '15 at 14:33
  • Hi Chris, thanks for your help but `UIAccessibilityElementFocusedNotification` doesn't seem to be available for iOS 8 ): – Cherie CH. Nov 21 '15 at 16:18
  • You can also track this using the UIAccessibilityFocus protocol. Same concept, just different API. The notification is very handy, too bad! – MobA11y Nov 22 '15 at 00:34
  • Hi Chris, yeah I was trying out the UIAccessibilityFocus protocol at the start, however it doesn't seem to work. I asked this [question](http://stackoverflow.com/questions/33845837/uiaccessibilityfocus-protocol-not-working) separately here, hoping that someone knows how to get it to work. Anyway, thanks for your help Chris, hope someone else will find your solution useful (: – Cherie CH. Nov 22 '15 at 06:47
  • I tried your solution but still have questions. I made an edit to the question. I placed a bounty on my question https://stackoverflow.com/questions/60008538/why-isnt-uiaccessibilitynotification-is-not-moving-to-correct-argument Can you take another look? – mfaani Feb 03 '20 at 16:00