简体   繁体   English

如何更改 swift 中的 VoiceOver 发音?

[英]How to change the VoiceOver pronunciation in swift?

I am trying to implement the accessibility to my ios project.我正在尝试实现对我的 ios 项目的可访问性。

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.例如,“speech”的正确发音是 [spiːtʃ],但我希望画外音在整个项目期间将所有单词 'speech' 与 'speak' [spiːk] 相同。

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'.我知道有一种方法可以设置我想将发音更改为“说话”的任何 UIElements 的可访问性 label。 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'.例如,我们从后端获取 label 文本,但我们永远不会知道 label 文本何时会是“语音”。 If I get the words 'speech' from the back end, I would like to hear voice-over read it as 'speak'.如果我从后端得到“speech”这个词,我想听到画外音将它读作“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'.每次,如果单词是“speech”,画外音将读作“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.只需从后端获取数据,并使用要替换的单词字典对字符串进行查找替换,然后将新版本的字符串添加为可访问性 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.最简单的解决方案是从后端返回第二个字符串,该字符串仅用于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如果您需要更多控制,可以将 AttributedString 作为accessibilityLabel 传递,其中包含许多用于控制发音的不同选项

https://medium.com/macoclock/ios-attributed-accessibility-labels-f54b8dcbf9fa 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) .将它们替换为属性字符串并使用accessibilitySpeechIPANotation为 VoiceOver 定义适当的语音(自 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.按照这个原理,您只是调整了您认为 VoiceOver 错误读出的单词的声音:对盲文功能没有影响。

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 .在我看来,必须执行这种操作,因为您的应用程序必须适应用户,而不是相反

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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