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

一世执手 提交于 2019-12-13 07:47:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!