0

Is it possible in any way to set an Accessibility Delegate on a Menu Item? My app uses text-to-speech and I want to execute some custom code before TalkBack starts speaking the content description of my menu item (which happens when the menu item gets accessibility focus). Otherwise, the text-to-speech from my app will clash with TalkBack's text-to-speech.

Update: My app fetches a sentence from a WebView, highlights it and reads it using the TTS engine. When the sentence has been spoken, the onDone() callback starts the same method but for the next sentence.

Since TalkBack and my app are using the same TTS engine, only one utterance is allowed to be spoken at a time. So my app is reading its WebView sentence per sentence, but then the user focuses on a Menu Item and TalkBack will read its description. Because my speech utterance was interrupted, onDone() will be called (onDone() cannot distinguish whether the utterance was fully spoken or simply interrupted), so the speakNextSentence() will be called, even though my previous sentence might be interrupted after only two words. I'd like to somehow put the isPaused boolean to true before the accessibility event of the Menu Item is fired.

private class ttsUtteranceListener extends UtteranceProgressListener {

    @Override
    public void onStart(String utteranceId) {
    }

    @Override
    public void onDone(final String utteranceId) {
        if (!isPaused) {   
            ...
            speakNextSentence();
            ...
        }
    }

    @Override
    public void onError(String utteranceId) {
    }
4

1 回答 1

1

除非小心处理,否则在 WCag 2.0 准则 2.2.2 下,您的应用程序所做的可能会被视为不可访问。

解决方案 1:根据本指南,处理这种情况的正确方法是为用户提供手动启动/停止/暂停内容的能力。这应该很容易实现。仅此一项就足够了,并且对于所有 3 个解决方案都是必需的。

解决方案 2:您执行此操作的另一种方法是,当您检测到可访问性引擎处于活动状态时,不进行自己的语音合成。使用 .将您的 webview 标记为 liveRegion ACCESSIBILITY_LIVE_REGION_POLITE。然后让对讲抓住你更新的 contentDescriptions,它应该包含当前突出显示的句子的文本。这让 TalkBack 的工作是确定何时宣布什么。这还有一个额外的好处,即即使您所在的区域处于活动状态并提供了大量反馈,它也会以可预测的方式对 TalkBack 用户进行操作。因此,它不太可能违反 WCag 2.2.2,但您仍然应该小心!并且可能仍然需要提供暂停内容的能力。

解决方案 3:Android MenuItem 没有实现所有可访问性 API 回调。例如,如果您的 MenuItems 是按钮,则解决方案是覆盖onRequestSendAccessibilityEvent并查找 TYPE_VIEW_ACCESSIBILITY_FOCUSED。但是 MenuItems 没有实现这个 API。因此,您可以编写自己的菜单,使用实现这些 API 的元素,并按照您想要的方式进行操作。不过,正如我之前提到的,我不推荐这种方法。这种方法很可能违反了 WCag 2.0 无障碍指南。

于 2015-02-18T18:31:10.357 回答