So I have a tts app and I'm trying to add the new iOS 17 personal voice as an option. I'm stuck on how to request auth to use voice. Here's what I have so far:
- (void)requestAuthorization
{
NSInteger row = [self.languagePicker selectedRowInComponent:0];
NSString *selected = [self.pickerData objectAtIndex:row];
self.languageChosen = selected;
if ([self.languageChosen isEqualToString:@"Personal"]) {
AVSpeechSynthesizer requestPersonalVoiceAuthorizationWithCompletionHandler:<#^(AVSpeechSynthesisPersonalVoiceAuthorizationStatus status)handler#>
}
}
I don’t know what to do after "requestPersonalVoiceAuthorizationWithCompletionHandler:"
any help will be really appreciated.
Here's how I'm doing it. So far so good.
-(void) MeTalkTPretty
{
if (@available(iOS 17.0, *)) {
[AVSpeechSynthesizer requestPersonalVoiceAuthorizationWithCompletionHandler:^(AVSpeechSynthesisPersonalVoiceAuthorizationStatus status) {
NSLog(@"AVSpeechSynthesis requestPersonalVoiceWCH returned %lu", (unsigned long)status);
if (status == AVSpeechSynthesisPersonalVoiceAuthorizationStatusAuthorized)
{
NSLog(@"Yippee! I can use personal voice");
// set this in case none of the voices are personal voice
voiceToUse = [AVSpeechSynthesisVoice voiceWithLanguage:AVSpeechSynthesisVoice.currentLanguageCode];
for (AVSpeechSynthesisVoice *thisVoice in [AVSpeechSynthesisVoice speechVoices])
{
if (thisVoice.voiceTraits == AVSpeechSynthesisVoiceTraitIsPersonalVoice)
{
voiceToUse = [AVSpeechSynthesisVoice voiceWithIdentifier:thisVoice.identifier];
NSLog(@"WINNER is personal voice %@ ", voiceToUse);
}
}
}
else
{
NSLog(@"darn, I can't use personal voice even though on iOS17");
voiceToUse = [AVSpeechSynthesisVoice voiceWithLanguage:AVSpeechSynthesisVoice.currentLanguageCode];
}
}];
}
else {
NSLog(@"Darn, I can't use personal voice because this device isn't running ios17");
voiceToUse = [AVSpeechSynthesisVoice voiceWithLanguage:AVSpeechSynthesisVoice.currentLanguageCode];
}
}