我想在AVSpeechSynthesizer说话的时候在我的应用程序上显示一个视图,当它停止说话时,这个视图就会消失。
-(void)speakText {
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
float speechSpeed = 0.12;
AVSpeechUtterance *synUtt = [[AVSpeechUtterance alloc] initWithString:textString];
[synUtt setRate:speechSpeed];
[synUtt setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:selectedVoice]];
[synthesizer speakUtterance:synUtt];
//BELOW TO APPEAR AND AND DISAPPEAR
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
_speakingScrollView.frame = CGRectMake(236, 675, _speakingScrollView.frame.size.width, _speakingScrollView.frame.size.height);
[self.view bringSubviewToFront:_speakingScrollView];
[UIView commitAnimations];
}我好像想不出该怎么做?我看过苹果文件显示
@property(nonatomic, readonly, getter=isSpeaking) BOOL speaking但我无法锻炼如何在我的应用程序中实现这一点。
发布于 2015-02-04 16:36:00
快速查看一下AVSpeechSynthesizer的文档就会发现它有一个delegate属性。
您应该设置delegate并实现AVSpeechSynthesizerDelegate协议,以便可以将语音合成器的事件通知给您。
事件,如
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didFinishSpeechUtterance:(AVSpeechUtterance *)utterance;和
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didStartSpeechUtterance:(AVSpeechUtterance *)utterance;考虑到你想知道它什么时候开始和停止,你会很感兴趣。还有一些被取消、暂停和继续的事件,您可能也希望实现这些事件来隐藏和显示UI。
https://stackoverflow.com/questions/28326487
复制相似问题