Objective C: 等待 AVSpeechSynthesizer 说完一个词

Objective C: Wait for AVSpeechSynthesizer until it finishes speaking a word

我需要禁用与用户的交互,直到应用程序完成说话。请参阅下面的示例代码:

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];
}

使用委托 (AVSpeechSynthesizerDelegate)。它会告诉您演讲何时结束,所以现在再次启用用户交互。