简体   繁体   中英

How to change the VoiceOver pronunciation in swift?

I am trying to implement the accessibility to my ios project.

Is there a way to correct the pronunciation of some specific words when the voice-over is turned on? For example, The correct pronunciation of 'speech' is [spiːtʃ], but I want the voice-over to read all the words 'speech' as same as 'speak' [spiːk] during my whole project.

I know there is one way that I can set the accessibility label of any UIElements that I want to change the pronunciation to 'speak'. However, some elements are dynamic. For example, we get the label text from the back-end, but we will never know when the label text will be 'speech'. If I get the words 'speech' from the back end, I would like to hear voice-over read it as 'speak'.

Therefore, I would like to change the setting for the voice-over. Every time, If the words are 'speech', the voice-over will read as 'speak'.

Can I do it?

Short answer.

Yes you can do it, but please do not.

Long Answer

Can I do it?

Yes, of course you can.

Simply fetch the data from the backend and do a find-replace on the string for any words you want spoken differently using a dictionary of words to replace, then add the new version of the string as the accessibility label.

SHOULD you do it?

Absolutely not.

Every time someone tries to "fix" pronunciation it ends up making things a lot worse.

I don't even understand why you would want screen reader users to hear "speak" whenever anyone else sees "speech", it does not make sense and is likely to break the meaning of sentences:

"I attended the speech given last night, it was very informative".

Would transform into:

"I attended the speak given last night, it was very informative"

Screen reader users are used to it.

A screen reader user is used to hearing things said differently (and incorrectly,). my guess is you have not been using a screen reader long enough to get used to the idiosyncrasies of screen reader speech.

Far from helping screen reader users you will actually end up making things worse.

I have only ever overridden screen reader default behaviour twice, once when it was a version number that was being read as a date and once when it was a password manager that read the password back and would try and read things as words.

Other than those very narrow examples I have not come across a reason to change things for a screen reader.

What about braille users?

You could change things because they don't sound right. But braille users also use screen readers and changing things for them could be very confusing (as per the example above of "speech").

What about best practices

"Give assistive technology users as similar an experience as possible to non assistive tech users". That is the number one guiding principle of accessibility, the second you change pronunciations and words, you potentially change the meaning of sentences and therefore offer a different experience.

Summing up

Anyway this is turning into a rant when it isn't meant to be (my apologies, I am just trying to get the point across as I answer similar questions to this quite often,), hopefully you get the idea, leave it alone and present the same info, I haven't even covered different speech synthesizers. language translation and more that using "unnatural" language can interfere with.

The easiest solution is to return a 2nd string from the backend that is used just for the accessibilityLabel.

If you need a bit more control, you can pass an AttributedString as the accessibilityLabel with a number of different options for controlling pronunication

https://medium.com/macoclock/ios-attributed-accessibility-labels-f54b8dcbf9fa

Can I do it?

Yes, you can and I do recommend it.

Here are the milestones I would follow:

  • When you receive the text from the backend, write a kind of regular expression to find the words whose pronunciation is incorrect.
  • Replace them as an attributed string and use the accessibilitySpeechIPANotation key in order to define the appropriate phonetic sound for VoiceOver (available since iOS11) .

More information about this topic is available if need be:

Following this rationale, you're just adapting the sound of the words you consider as incorrectly read out by VoiceOver: no impact on the braille feature.

In my view, this kind of action has to be done because it's your application that must adapt to the users and not the other way around .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM