问题
I need to disable the interaction with the user until the app finishes speaking. see example code below:
self.view.userInteractionEnabled = NO;
[self speak :@"wait for me to speak"];
self.view.userInteractionEnabled = YES;
-(void)speak:(NSString*)word
{
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:word];
utterance.rate = AVSpeechUtteranceMinimumSpeechRate;
utterance.rate = 0.2f;
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage
[AVSpeechSynthesisVoice currentLanguageCode]];
[synthesizer speakUtterance:utterance];
}
回答1:
Use the delegate (AVSpeechSynthesizerDelegate). It tells you when the speech is over, so now enable user interaction again.
来源:https://stackoverflow.com/questions/28335310/objective-c-wait-for-avspeechsynthesizer-until-it-finishes-speaking-a-word