问题描述
现在,我的应用实现了AVSpeechSynthesizer
来读取每个屏幕的说明.启用画外音辅助功能时,该应用程序也会考虑在内.
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.
我现在面临的问题是文本到语音功能与画外音功能重叠.是否有一种解决方案可以检测到,当用户导航到屏幕上的另一个元素时,TTS停止讲话,或者当TTS在讲话时,直到TTS完成时才进行画外音(不过,首选前者).
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).
当前开发是使用Swift在iOS 8上进行的.
The current development is on iOS 8, using Swift.
推荐答案
选项1
通过观察UIAccessibilityElementFocusedNotification
通知,您可以侦听新元素的焦点
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.
优点:为VoiceOver用户提供了很多控制权.
Pros: Gives the VoiceOver user a lot of control.
缺点:您不知道VoiceOver何时读完新集中的控件,因此您不能用它来中断和重新启动通知.
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.
选项2
您可以通过发布告诉VoiceOver暂停并重新启动
You can tell VoiceOver to pause and restart by posting
UIAccessibilityPostNotification(UIAccessibilityPauseAssistiveTechnologyNotification, nil);
在您宣布之前和
UIAccessibilityPostNotification(UIAccessibilityResumeAssistiveTechnologyNotification, nil);
完成后.
优点:您的公告将被完整阅读.
Pros: Your announcement will get read off in it's entirety.
缺点:暂停VoiceOver时,您会失去用户的控制权.
Cons: You take control out of the users hands when you pause VoiceOver.
推荐
如果您的公告很短,那么暂停并恢复AT并不是一个糟糕的解决方案.否则,我建议允许VoiceOver用户通过监听UIAccessibilityElementFocusedNotification
事件来中断/取消您的公告,并在收到它们时取消任何活动的公告.
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.
这篇关于在旁白说话时,如何停止文字转语音,在Swift中反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!