Voice Control Activation  and Accessibility Priority Announcements using swiftUI

Voice Control Activation and Accessibility Priority Announcements using swiftUI


In this article, we'll delve into two distinct aspects of SwiftUI's accessibility toolkit. The first focuses on providing alternative voice commands for app elements, while the second emphasizes prioritizing accessibility announcements for a seamless user experience. Let's explore each in detail.

1. Voice Control Activation with .accessibilityInputLabels

The .accessibilityInputLabels attribute in SwiftUI allows developers to specify alternative voice commands for Voice Control, enabling users to activate specific elements within the app using different spoken phrases.

Why It Matters

  • User-Friendly: Makes the app easier to navigate for all users, including those with disabilities.
  • Voice Activation: Allows users to control the app using voice commands, enhancing the user experience.
  • Ease of Use: Provides users with multiple ways to voice-activate a feature.
  • Inclusivity: Makes the app more accessible to users with disabilities.

Key Terms

  • Voice Control: A feature in iOS that allows users to navigate and interact with their device using spoken commands.
  • Accessibility Label: A text description of a UI element.
  • Alternative Voice Commands: Additional phrases that can trigger an action.

Example

Imagine an app that listens to your voice, much like Siri or Alexa. In this app, developers have the ability to assign multiple voice commands to a single action or button. So, instead of just one way to activate a feature, there are several voice options. For example, if there's a button in the app to start a Virtual assistant, you don't have to remember a specific phrase. You could say "Virtual assistant," "Assistant," or even "Open Assistant," and any of these commands would activate the same feature. It's all about giving you flexibility in how you interact with the app using your voice.

How to Implement

Step 1: Identify the Element

First, identify the button or feature you want to make voice-activatable. For example, let’s consider a button that activates a virtual assistant feature in the app.

Step 2: Add Accessibility Label

Add an accessibility label to the button. This label serves as the default voice command.


Code Snippet:


.accessibilityLabel("Virtual  assistant")        

Step 3: Add Alternative Voice Commands

Think of alternative phrases that users might use to trigger the button. Use .accessibilityInputLabels to add alternative voice commands. These are additional phrases that can also trigger the button.

Code Snippet:

.accessibilityInputLabels(["Assistant", "Open Assistant", "Virtual Assistant"])
        


Step 4: Test and Revise

After implementation, test the feature to make sure all voice commands work as expected.

Final Code Snippet

Here’s how the final code might look:

Button(action: {
    // Trigger Virtual assistant multi-modal feature
}) {
    Text("Activate Assistant")
}
.accessibilityLabel("Virtual  assistant")
.accessibilityInputLabels(["Assistant", "Open Assistant", "Virtual  Assistant"])        

Best Practices

  • Be Descriptive: Choose voice commands that are descriptive and easy to remember.
  • Be Consistent: Ensure that the alternative voice commands are consistent with the feature they activate.
  • User Testing: Always test the voice commands with real users to ensure they are intuitive and functional.

Additional Guidelines

Keep It Short

  • What to Do: Aim for brevity while maintaining clarity.
  • Why: Shorter commands are easier to say and quicker for the system to recognize.

Use Common Phrases

  • What to Do: Incorporate phrases commonly used in everyday language.
  • Why: Common phrases are more likely to be the first choice for users when voice-activating a feature.

Avoid Jargon

  • What to Do: Steer clear of technical or industry-specific language.
  • Why: Accessibility is for everyone; not all users will understand specialized terminology.



2. Accessibility Announcements with .accessibilitySpeechAnnouncementPriority

The .accessibilitySpeechAnnouncementPriority attribute in SwiftUI provides developers the capability to prioritize specific accessibility announcements. This is especially beneficial for users who depend on VoiceOver or similar assistive technologies, ensuring they receive the most crucial information promptly during their app interactions.

Why It Matters

  • User Engagement: Tailored announcements can guide users through the application, enhancing their overall experience.
  • Efficiency: Prioritized announcements ensure that users receive the most critical information first.
  • Inclusivity: Such features ensure that applications cater to all users, including those with disabilities.

Key Terms

  • Accessibility Notification API: An API that allows developers to send out specific announcements to users using assistive technologies.
  • Announcement Priority: The ability to set the importance of announcements as high, default, or low.

Example

Here's an example to illustrate: Imagine using a mobile app designed to help you deposit checks by simply taking a photo. As you prepare to snap a picture of the front of your check, the app gently reminds you with a message: "You are scanning the Front Side of the Check." On the screen, there's a button labeled "Scan Check." When you tap this button, the app assists you with voice messages. It confirms you're capturing the front, ensures it's getting a focused image, and then cheerfully announces when the check's image is successfully taken. These voice cues are designed to guide users every step of the way, making the experience smooth and user-friendly.

How to implement

Implement the Button with Accessibility Announcements


1. Default Priority: Confirming the Front Side


var confirmFrontSideAnnouncement = AttributedString("You are scanning the Front Side of the Check")swift
        

2. Low Priority: Locking Focus on Front Side

var frontSideFocusLockedAnnouncement: AttributedString {
    var focusString = AttributedString("Focus Locked on Front Side of Check")
    focusString.accessibilitySpeechAnnouncementPriority = .low
    return focusString
}        

Once the camera locks its focus on the check, a low-priority announcement is made. This ensures the user knows that the app is preparing to capture the image.

3. High Priority: Front Side Successfully Captured

var frontSideCapturedAnnouncement: AttributedString {
    var captureString = AttributedString("Front Side of Check Successfully Captured")
    captureString.accessibilitySpeechAnnouncementPriority = .high
    return captureString
}        

After capturing the image, a high-priority announcement is made to let the user know that the image of the front side of the check has been successfully captured. This is the most crucial information, ensuring the user knows the task is complete.

The main button implementation:

var body: some View {
    Button(action: {
        // Confirming Front Side of Check
        AccessibilityNotification.Announcement(confirmFrontSideAnnouncement).post()
        // Locking Focus on Front Side
        AccessibilityNotification.Announcement(frontSideFocusLockedAnnouncement).post()
        // Front Side Captured
        AccessibilityNotification.Announcement(frontSideCapturedAnnouncement).post()
    }) {
        Text("Scan Check")
    }
}        

By setting different priorities for these announcements, the app ensures that users, especially those using assistive technologies, receive the most crucial information at the right time, enhancing their overall experience.

Best Practices

  • Clear Announcements: Ensure that announcements are clear and provide meaningful information to the user.
  • User Testing: Regularly test with real users, especially those using assistive technologies, to ensure the announcements are beneficial.

Additional Guidelines

  • Keep It Short: Announcements should be concise and to the point. Users can quickly understand and act upon short and clear announcements.
  • Prioritize Correctly: Use the priority setting wisely. It ensures that users receive the most important announcements first.
  • Avoid Technical Jargon: Use simple language in announcements. Not all users will understand technical or industry-specific terms.

Julian Kittelson-Aldred

Digital Accessibility ? Inclusive Design ? iOS ? Android ? Web

1 年

This is great, thanks, Juny! I didn't know we could specify alternative voice commands, this is great to know.

Stefano Diano

Global Sales & Marketing Professional | Expert Hotelier | Business Development | International Recruiter | Linkedin Publisher | Italy - Canada - Korea - China - Thailand |

1 年

An amazing article and guide Juny Kallukalam thanks for sharing!

Rushikesh Suradkar

Member of Technical Staff at MSX

1 年

This is a great article! Well done!

要查看或添加评论,请登录

社区洞察