SwiftUI 让 Voiceover 读取街道地址

huangapple go评论125阅读模式
英文:

SwiftUI Make Voiceover Read Street Address

问题

Voiceover 如何正确朗读街道地址?我已经尝试了很多方法,但迄今为止都没有成功。最终,我创建了一个复杂的 accessibilityLabel,但效果仍然不佳。

例如,如果你有以下地址:

123 Main St.
Los Angeles, CA 90210
United States

我希望 Voiceover 朗读为:

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

但实际上它目前朗读为:

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

我可以使用 .speechSpellsOutCharacters() 修饰符,这是我在前面提到的 accessibilityLabel 中拆分内容时所用的方法,但这实际上只对邮政编码有效,对其他部分无济于事。

有什么建议吗?

英文:

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?

答案1

得分: 1

你可以强制屏幕阅读器以拼音方式阅读,但强烈不建议。如果你以拼音拼写单词或嵌入空格以强制发音,会给盲文用户提供不正确的信息。

屏幕阅读器用户可以逐个字符地阅读内容,所以如果他们听到不对的东西,他们会逐个字母地阅读。虽然这不是很好的体验,但试图欺骗屏幕阅读器以你认为应该阅读的方式总会给其他用户带来问题。

另外,用户的屏幕阅读器设置可以影响它如何宣布事物。通常,数字的朗读在“详细程度”设置中进行控制。

在提出所有这些警告之后,我建议不要执行以下操作,尽管它可以解决你的“问题”。

<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>

“sr-only”类并没有什么特别之处。它只是一个常用的名称,用于样式化文本,以使其在视觉上不可见,但屏幕阅读器仍然可以阅读它。第一个 <span> 上的 aria-hidden 将该文本从屏幕阅读器中隐藏。你可以在 https://stackoverflow.com/questions/19758598/what-is-sr-only-in-bootstrap-3 中了解更多关于“sr-only”的信息。

这将强制“123”被宣布为“一 二 三”,因为数字之间有空格。它还拼出“street”而不是使用“st.”。但盲文用户将阅读“一 空格 二 空格 三”,这在阅读地址时会令人困惑。

你可以在我几年前回答的 https://stackoverflow.com/questions/53547488/pronounce-abbreviations-or-initialisms-as-individual-characters-in-androids-talk/53547759#53547759 中了解更多关于这为什么是个糟糕的想法的信息。

英文:

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".

&lt;span aria-hidden=&quot;true&quot;&gt;123 Main St. Los Angeles, CA 90210 United States&lt;/span&gt;
&lt;span class=&quot;sr-only&quot;&gt;1 2 3 Main Street, Los Angeles, California 9 0 2 1 0 United States&lt;/span&gt;

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 &lt;span> hides that text from the screen reader. You can see more about "sr-only" at https://stackoverflow.com/questions/19758598/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 https://stackoverflow.com/questions/53547488/pronounce-abbreviations-or-initialisms-as-individual-characters-in-androids-talk/53547759#53547759 from a few years ago.

huangapple
  • 本文由 发表于 2023年5月14日 23:55:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定