Here is my code for text-to-speech. Everything is working fine below iOS 11. But in iOS 11 delegate methods are not being called.
AVSpeechSynthesizerDelegate
is set accurately. (As it is working below iOS 11)
On button tap
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
synthesizer.delegate = self;
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:stringToSpeech];
[utterance setRate:AVSpeechUtteranceDefaultSpeechRate];
[utterance setPitchMultiplier:1];
[utterance setVolume:1];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
[synthesizer speakUtterance:utterance];
These are delegate methods I have implemented.
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"finished");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"Started");
}
Did someone face this issue? Any help will be greatly appreciated.
I m testing on iOS 11.0.3, with Xcode 9.0
Your synthesizer
object must be a property for that to work :).
Either make your AVSpeechSynthesizer
instance, which is synthesizer
like so:
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
or like this with readwrite.
@property (readwrite, strong, nonatomic) AVSpeechSynthesizer *synthesizer;
Let me know if this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With