Tailor VoiceOver Speech Properties in SwiftUI
Written by Team Kodeco
VoiceOver is a screen-reading technology provided by Apple that allows people with visual impairments to interact with their devices. One of the important aspects of making an app accessible is making sure that VoiceOver reads out your app’s content in a way that makes sense to the user. SwiftUI provides several modifiers that allow you to control VoiceOver’s speech properties.
In this cookbook entry, you’ll learn how to adjust VoiceOver’s speech pitch, control punctuation announcement, manage speech announcement queueing and dictate character spelling for text views.
Let’s create a simple example where we demonstrate these speech properties on a SwiftUI Text
view:
struct ContentView: View {
var body: some View {
Text("Hello, World! How are you today?")
.font(.largeTitle)
.speechAdjustedPitch(0.8) // 1.0 is the normal pitch, lower values lower the pitch
.speechAlwaysIncludesPunctuation(true) // Always announce punctuation marks
.speechAnnouncementsQueued(true) // Queue announcements rather than interrupting
.speechSpellsOutCharacters(false) // Do not spell out characters
}
}
Here’s what your preview should look like:
In this example, you have a Text
view that says, “Hello, World! How are you today?”. Using SwiftUI’s accessibility modifiers, you’re able to:
- Adjust the pitch of VoiceOver’s speech with the
speechAdjustedPitch
modifier. A value of 1.0 represents the normal pitch. - Control whether VoiceOver always announces punctuation marks with
speechAlwaysIncludesPunctuation
. - Decide whether pending announcements should be queued rather than interrupting the current speech with
speechAnnouncementsQueued
. - Dictate whether the content should be spelled out character by character with
speechSpellsOutCharacters
.
With these SwiftUI accessibility modifiers, you have the flexibility to tailor VoiceOver’s speech properties according to the needs of your app, enhancing the accessibility of your app for users with visual impairments.