画外音无法正确读取电话号码 [英] Voice over doesn't read phone number properly

查看:33
本文介绍了画外音无法正确读取电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的电话号码

I have phone number in below format

1-1xx-2xx-9565

目前VO读为(停顿)一xx(停顿)二xx(停顿)减九千五百六十五".

Currently VO read it as "One (pause) One x x (pause) two x x (pause) minus nine thousand five hundred sixty five".

VO 应该读作One(停顿)One xx(停顿)2 xx(停顿)九五六五".

VO should read it as "One (pause) One x x (pause) two x x (pause) nine five six five".

可能是什么问题?这是错误的电话格式吗?

What could be the problem? Is this wrong phone format?

推荐答案

让我们分解正在发生的事情.VoiceOver 不知道您呈现的文本是电话号码,而是将其视为文本句子.在该文本中,它试图找到不同的组件并适当地阅读它们.例如,文本 buy 60 cantaloupes" 有 3 个组成部分,购买"、60"和哈密瓜".第一个是文本,作为文本阅读,第二个是纯数字,最好读为六十",第三个作为文本阅读.

Let's break down what is happening. VoiceOver doesn't know that the text you are presenting is a phone number and treats it like a sentence of text. In that text it tries to find distinct components and read them appropriately. For example, the text "buy 60 cantaloupes" has 3 components, "buy", "60", and "cantaloupes". The first is text and is read as text, the second is purely numerical and is best read out as "sixty", and the third is read as text.

(我不是在谈论实际的实现,只是推理.)

(I'm not talking about actual implementation, just reasoning.)

如果您从左到右阅读 1-1xx-2xx-9565,那么第一个不同的组件是1";它本身是数字并且读作1".如果电话号码以12-1xx"开头那么第一个组件将被读作十二".因为它纯粹是数字.

If you read 1-1xx-2xx-9565 from the left to the right then the first distinct component is "1" which in it self is numerical and is read as "1". If the phone number would have started with "12-1xx" then the first component would have been read as "twelve" because its purely numerical.

下一个组件是1xx";或-1xx"取决于你如何看待它.在任何一种情况下,它都是数字和字母的组合,例如它不是纯粹数字,因此作为文本读出.如果包含-"该组件中的 被解释为未读出的连字符.这就是为什么-"永远不会为该组件读出.下一个组件(-2xx")的处理方式相同.

The next component is "1xx" or "-1xx" depending on how you look at it. In either case it is a combination of numbers and letters, e.g. it is not purely numerical and is thus read out as text. If you include the "-" in that component is interpreted as a hyphen which isn't read out. That is why the the "-" is never read out for that component. The next component ("-2xx") is treated in the same way.

最终组件是-9565";结果证明这是一个有效数字.正如哈密瓜句子中所见,VoiceOver 将其读作一个数字,在这种情况下,-"不再解释为连字符,而是解释为减号".

The final component is "-9565" which turns out to be a valid number. As seen in the cantaloupe sentence, VoiceOver reads this as a number in which case the "-" is no longer interpreted as a hyphen but as a "minus sign".

在与 Voice Over 一起使用的应用程序中的任何标签、视图或其他元素上,您可以提供自己的可访问性标签";当您更多地了解您希望如何阅读文本时.这是通过简单地将您自己的字符串分配给 accessibilityLabel 属性来完成的.

On any label, view or other element in your application that is used with Voice Over, you can supply your own "accessibility label" when you know more about how you want the text to be read. This is done by simply assigning your own string to the accessibilityLabel property.

现在,您可以通过多种不同的方式创建一个合适的字符串,在您的情况下,一个非常简单的方法就是在各处添加空格,以便单独读取每个数字.然而,我觉得这有点脆弱,所以我继续使用数字格式化程序将各个数字转换为它们的文本表示.

Now, you can create a suitable string in many different ways, a very simple one in your case would be to just add spaces everywhere so that each number is read individually. However, it seems a bit fragile to me, so I went ahead and used a number formatter to translate the individual numbers to their textual representations.

NSString *phoneNumber = @"1-1xx-2xx-9565";

// we want to know if a character is a number or not
NSCharacterSet *numberCharacters = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];

// we use this formatter to spell out individual numbers
NSNumberFormatter *spellOutSingleNumber = [NSNumberFormatter new];
spellOutSingleNumber.numberStyle = NSNumberFormatterSpellOutStyle;

NSMutableArray *spelledOutComonents = [NSMutableArray array];
// loop over the phone number add add the accessible variants to the array
[phoneNumber enumerateSubstringsInRange:NSMakeRange(0, phoneNumber.length)
                                options:NSStringEnumerationByComposedCharacterSequences
                             usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                 // check if it's a number
                                 if ([substring rangeOfCharacterFromSet:numberCharacters].location != NSNotFound) {
                                     // is a number
                                     NSNumber *number = @([substring integerValue]);
                                     [spelledOutComonents addObject:[spellOutSingleNumber stringFromNumber:number]];
                                 } else {
                                     // is not a number
                                     [spelledOutComonents addObject:substring];
                                 }
                             }];
// finally separate the components with spaces (so that the string doesn't become "ninefivesixfive".
NSString *yourAccessiblePhoneNumber = [spelledOutComonents componentsJoinedByString:@" "];

我运行的结果是

one - one x x - two x x - nine five six five

如果您需要对您的电话号码进行其他修改以使其正确读取,那么您可以这样做.我怀疑你会在你的应用中不止一个地方使用它,所以创建一个自定义的 NSFormatter 可能是一个好主意.

If you need to do other modifications to your phone numbers to get them to read appropriately then you can do that. I suspect that you will use this is more than one place in your app so creating a custom NSFormatter might be a good idea.

在 iOS 7 上,您还可以在属性字符串上使用 UIAccessibilitySpeechAttributePunctuation 属性来更改它的发音.

On iOS 7 you can also use the UIAccessibilitySpeechAttributePunctuation attribute on an attributes string to change how it is pronounced.

可以应用于属性字符串中的文本以修改该文本的发音方式的属性.

Speech Attributes for Attributed Strings

Attributes that you can apply to text in an attributed string to modify how that text is pronounced.

UIAccessibilitySpeechAttributePunctuation

该键的值是一个 NSNumber 对象,您应该将其解释为布尔值.当值为 YES 时,将朗读文本中的所有标点符号.您可以将其用于标点符号相关的代码或其他文本.

The value of this key is an NSNumber object that you should interpret as a Boolean value. When the value is YES, all punctuation in the text is spoken. You might use this for code or other text where the punctuation is relevant.

适用于 iOS 7.0 及更高版本.

Available in iOS 7.0 and later.

UIAccessibilityConstants.h 中声明.

这篇关于画外音无法正确读取电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆