How can i add/change speech voice gender to iOS app in swift? I am using AVSpeechSynthesisvoice Class for getting speech voices

Viewed 2194

I have created an app with speech voice feature using AVSpeechSynthesizer & displaying a list of languages from AVSpeechSynthesisVoice: speechVoices() function in a TableView. The user can select speech language from the TableView.

The next thing i wanted to achieve is to add speech gender so that user can switch between default Male or Female voices like in Siri app. I do not want to make it complex so just looking for default Male or Female voices.

The voices returned from speechVoices() have a default Male or Female voice specific to each voice.

Can I change it anyhow ? I have placed a UIPickerView on app settings page to select between male and Female voices.

However, I did some research but could not found any documentation. Seems there is no such support available till latest iOS release.

Did anyone tried to implement such feature so far?

1 Answers
    //NSArray* voices = AVSpeechSynthesisVoice.speechVoices;
    //voice identifier inspection reports
    //com.apple.ttsbundle.Samantha-compact
    //com.apple.speech.synthesis.voice
    //AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:text];
    //Replace hard-coded name with any available in the list pulled from the speechVoices array

    NSUInteger idx = [AVSpeechSynthesisVoice.speechVoices indexOfObjectPassingTest:^BOOL(AVSpeechSynthesisVoice * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
      return [obj.identifier containsString:@"Samantha"];
    }];
    if (idx > -1) {
      AVSpeechSynthesisVoice* voice = AVSpeechSynthesisVoice.speechVoices[idx];
      utterance.voice = voice;
    }
Related