0

Is there any solution to making voiceover properly read a street address? I have tried a bunch of stuff and nothing is working thus far. I ended up creating a crazy accessibilityLabel but it's still not great.

For example, if you have an address of:

123 Main St. Los Angeles, CA 90210 United States

I want voiceover to read:

"one two three main street, los angeles california nine zero two one zero, united states"

but it current reads

"one hundred twenty three main s t, los angeles c a ninety thousand two hundred ten, united states"

I can use the .speechSpellsOutCharacters() modifier, which is what I did when splitting up things for the accessibilityLabel I mentioned earlier but that really only works for the zip code and nothing else.

Any ideas?

kittonian
  • 1,020
  • 10
  • 22
  • 1
    https://developer.apple.com/documentation/foundation/attributescopes/accessibilityattributes/3850595-accessibilityspeechspellsoutchar or use space between numbers. – user1046037 May 14 '23 at 16:12
  • No need to provide a link to documentation that doesn't solve the issue and literally explains what I've already said I've done in my original post. – kittonian May 14 '23 at 18:35

1 Answers1

1

You can force a screen reader to read phonetically but it's strongly discouraged.

If you spell things phonetically or embed spaces to force a certain pronunciation, it will give incorrect information to a braille user.

A screen reader user can read content a character at a time so if they hear something that doesn't sound right, they just walk it letter by letter. It's not great a experience, but trying to trick the screen reader to read things the way you think they should be read will always cause a problem for another user.

Also, the user's screen reader settings can affect how it announces things. Having numbers read is often controlled in the "verbosity" setting.

With all those caveats in place, I recommend not doing the follow, although it would fix your "problem".

<span aria-hidden="true">123 Main St. Los Angeles, CA 90210 United States</span>
<span class="sr-only">1 2 3 Main Street, Los Angeles, California 9 0 2 1 0 United States</span>

The "sr-only" class is not anything special. It's just a common name used for a class that styles text so that it is not visually visible but a screen reader can still read it. The aria-hidden on the first <span> hides that text from the screen reader. You can see more about "sr-only" at What is sr-only in Bootstrap 3?

This will force "123" to be announced as "one two three" because there are spaces between the numbers. It also spells out "street" instead of using "st.". But a braille user will read "one space two space three", which will be confusing when reading an address.

You can see more about why this is a bad idea in my answer to Pronounce abbreviations or initialisms as individual characters in androids Talkback accessibility from a few years ago.

slugolicious
  • 15,824
  • 2
  • 29
  • 43
  • Thanks, that's not what I was looking for and I agree that you should never do it this way. When you have a TextField you can use .textContentType(.streetAddress1) for example and voiceover will read it properly. However, this doesn't work for just reading regular text. I was hoping there was some sort of modifier or trait that would tell voiceover how to properly read an address, but after looking at the Maps app and hearing it also read an address improperly, it appears that it not possible. – kittonian May 14 '23 at 18:34
  • 1
    Sorry, I overlooked the swiftui tag and glossed over swiftui in the question and assumed an html question. – slugolicious May 14 '23 at 22:15