Voice message does not read phone number correctly

I have a phone number in the format below

1-1xx-2xx-9565

VO is currently reading it as " One (pause) One xx (pause) two xx (pause) minus nine thousand five hundred sixty five ."

VO should be read as " One (pause) One xx (pause) two xx (pause) nine five six five ."

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

+4
source share
4 answers

, . VoiceOver , , , . . , "buy 60 cantaloupes" 3 : "buy", "60" "cantaloupes". - , - "", - .

.

( , .)

1-1xx-2xx-9565 , - "1", "1". "12-1xx", "", .

- "1xx" "-1xx" , . , . , , . "-" , , . "-" . ( "-2xx" ) .

"-9565", . , VoiceOver , "-" , "".

VoiceOver

, , Voice Over, , , , . accessibilityLabel.

-, , . , , , .

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


iOS 7 UIAccessibilitySpeechAttributePunctuation , .

, , , .

UIAccessibilitySpeechAttributePunctuation

- NSNumber, . YES, . , .

iOS 7.0 .

UIAccessibilityConstants.h.

+9

Swift

    public func retrieveAccessiblePhoneNumber(phoneNumber: String) -> String {
    // We want to know if a character is a number or not
    let characterSet = NSCharacterSet(charactersInString: "0123456789")

    // We use this formatter to spell out individual numbers
    let numberFormatter = NSNumberFormatter()
    numberFormatter.numberStyle = .SpellOutStyle

    var spelledOutComponents = [String]()
    let range = Range<String.Index>(start: phoneNumber.startIndex, end: phoneNumber.endIndex)

    // Loop over the phone number add add the accessible variants to the array
    phoneNumber.enumerateSubstringsInRange(range,
        options: NSStringEnumerationOptions.ByComposedCharacterSequences) { (substring, substringRange, enclosingRange, stop) -> () in
            // Check if it a number
            if let substr = substring where substr.rangeOfCharacterFromSet(characterSet) != nil {
                if let number = Int(substr) {
                    // Is a number
                    let nsNumber = NSNumber(integer: number)
                    spelledOutComponents.append(numberFormatter.stringFromNumber(nsNumber)!)
                }
            } else {
                // Is not a number
                spelledOutComponents.append(substring!)
            }
    }

    // Finally separate the components with spaces (so that the string doesn't become "ninefivesixfive".
    return spelledOutComponents.joinWithSeparator(" ")
}
0

, ",".

String :

extension String
{
    /// Returns string suitable for accessibility (voice over). All characters will be spelled individually.
    func stringForSpelling() -> String
    {
        return stringBySeparatingCharactersWithString(",")
    }


    /// Inserts a separator between all characters
    func stringBySeparatingCharactersWithString(separator: String) -> String
    {
        var s = ""
        // Separate all characters
        let chars = self.characters.map({ String($0) })

        // Append all characters one by one
        for char in chars {
            // If there is already a character, append separator before appending next character
            if s.characters.count > 0 {
                s += separator
            }
            // Append next character
            s += char
        }

        return s
    }
}

:

myLabel.accessibilityLabel = myString.stringForSpelling()
0
source

Just add a comma to each digit of the last number and after the last digit. this will make the voice read out the last number in the same way as the previous digits.

example of your number: - 1-1xx-2xx-9565 availability label: - 1-1xx-2xx-9,5,6,5,

0
source

Source: https://habr.com/ru/post/1526898/


All Articles