How to determine if an iOS device has downloaded a voice file?

I’m working on a text-to-speech application and am trying to add an option for using Alex’s voice, which is new to iOS 9. I need to determine if the user has downloaded Alex’s voice in Settings → Accessibility. I can’t figure out how to do this.

if ([AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex] == "Not Found" ) {
    // Do something...
}

The reason is the voices of other languages ​​that are standard, play at a certain speed, different from Alex's voice. Therefore, I have a working application, but if the user has not downloaded the voice, iOS automatically uses the main voice by default, but it plays the wrong speed. If I can detect that the voice has not been downloaded, I can compensate for the difference and / or inform the user.

+4
source share
2 answers

Okay, so I think I overdid it and thought it was harder. The solution was simple.

if (![AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex]) {
        // Normalize the speech rate since the user hasn't downloaded the voice and/or trigger a notification that they need to go into settings and download the voice. 
    }

Thanks to everyone who looked at this, and to @CeceXX for editing. Hope this helps someone else.

+3
source

Here is one way to do it. Let us insert an example with Alex:

- (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 skips all installed voices and requests each voice name. If Alex is among them, he set.

Other values ​​you can request are “language” (returns a language code such as en-US) and quality (1 = standard, 2 = enhanced).

0
source

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


All Articles