How to check if the Alex Voice is installed in iOS

Talk-Icon-512Alex is Apple’s high-quality voice that users can download and use with VoiceOver and any text-to-speech application, including the native AVSpeechSynthesizer methods.

However, Alex is an optional file that users can download if they wish, and he’s rather large too (about 900MB). Hence we can’t rely on this voice being available.

While your iOS app can request to play an utterance using Alex, iOS will default to the low-quality standard voice if Alex is not available. So how can we check if he’s around?

Here’s a quick method that lets us do just that: it checks if the Alex voice as been downloaded to the device, and lets you react accordingly – perhaps by letting the user know that an enhancement is available and how to get it:

- (void)checkForAlex {
    
    // is Alex installed?
    BOOL alexInstalled = NO;
    NSArray *voices = [AVSpeechSynthesisVoice speechVoices];
    
    for (id voiceName in voices) {
        
        if ([[voiceName valueForKey:@"name"] isEqualToString:@"Alex"]) {
            alexInstalled = YES;
        }
    }
    
    // react accordingly
    if (alexInstalled) {
        NSLog(@"Alex is installed on this device.");
    } else {
        NSLog(@"Alex is not installed on this device.");
    }
}

This method loops through all installed voices and queries each voice’s name. If Alex is among them, he’s installed. You can also query other names (each voice has a name identifier), and if an “enhanced” version is available using the “quality” parameter ( 1 = standard, 2 = enhanced).

Query the “language” parameter to see which languages are available for speech on the current device (returns a language code like en-US).

For testing: here’s a quick method that writes all available voice names and parameters out as log messages:

- (void)showAllVoices {
    
    // display a list of all available voices
    NSArray *voices = [AVSpeechSynthesisVoice speechVoices];
    for (id voiceName in voices) {

        NSLog(@"Language Code: %@", [voiceName valueForKey:@"language"]);
        NSLog(@"Name: %@", [voiceName valueForKey:@"name"]);
        NSLog(@"Quality: %@", [voiceName valueForKey:@"quality"]);
        NSLog(@"Identifier: %@", [voiceName valueForKey:@"identifier"]);
        NSLog(@"-----------------------");
    }
}




Leave a Reply