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

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

问题描述

我的电话号码格式如下

1-1xx-2xx-9565

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应将其读作一个(暂停) 一个xx (暂停)两个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不知道您呈现的文本是电话号码,并将其视为文本句子。在该文本中,它试图找到不同的组件并适当地读取它们。例如,文本购买60个哈密瓜有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.


属性字符串的语音属性



您可以应用于属性字符串中的文本以修改h的属性该文本发音。

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天全站免登陆