Reputation: 311
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?
Upvotes: 10
Views: 2740
Reputation: 996
I think you don't have that information, and each voice is male or female, so you would have to categorise all available voices for the languages your are working with, so that on runtime you can sort them using this information. That's something I would be very willing to use on my app.
Upvotes: 0
Reputation: 13181
//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;
}
Upvotes: -1