首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVSpeechSynthesizer -如果AVSpeechSynthesizer在讲话&如果已经停止讲话

AVSpeechSynthesizer -如果AVSpeechSynthesizer在讲话&如果已经停止讲话
EN

Stack Overflow用户
提问于 2015-02-04 16:31:11
回答 1查看 1.3K关注 0票数 0

我想在AVSpeechSynthesizer说话的时候在我的应用程序上显示一个视图,当它停止说话时,这个视图就会消失。

代码语言:javascript
复制
-(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];

}

我好像想不出该怎么做?我看过苹果文件显示

代码语言:javascript
复制
@property(nonatomic, readonly, getter=isSpeaking) BOOL speaking

但我无法锻炼如何在我的应用程序中实现这一点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-04 16:36:00

快速查看一下AVSpeechSynthesizer的文档就会发现它有一个delegate属性。

您应该设置delegate并实现AVSpeechSynthesizerDelegate协议,以便可以将语音合成器的事件通知给您。

事件,如

代码语言:javascript
复制
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
 didFinishSpeechUtterance:(AVSpeechUtterance *)utterance;

代码语言:javascript
复制
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
  didStartSpeechUtterance:(AVSpeechUtterance *)utterance;

考虑到你想知道它什么时候开始和停止,你会很感兴趣。还有一些被取消、暂停和继续的事件,您可能也希望实现这些事件来隐藏和显示UI。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28326487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档