目标C:等待AVSpeechSynthesizer,直到它说完一个单词

时间:2015-02-05 02:43:52

标签: ios objective-c avspeechsynthesizer

我需要禁用与用户的互动,直到应用完成发言。请参阅下面的示例代码:

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 个答案:

答案 0 :(得分:1)

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