gpt4 book ai didi

ios - AVSpeechSynthesizer - 如果 AVSpeechSynthesizer 正在说话并且已经停止说话

转载 作者:行者123 更新时间:2023-11-29 02:19:33 24 4
gpt4 key购买 nike

我想在 AVSpeechSynthesizer 说话时在我的应用程序上显示一个 View ,并在它停止说话时让该 View 消失。

-(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

但我无法弄清楚如何将其实现到我的应用程序中。

最佳答案

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

您应该设置delegate 并实现AVSpeechSynthesizerDelegate 协议(protocol),这样您就可以收到语音合成器事件的通知。

事件如

- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didFinishSpeechUtterance:(AVSpeechUtterance *)utterance;

- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didStartSpeechUtterance:(AVSpeechUtterance *)utterance;

考虑到您想知道它何时开始和停止,这对您来说是最有趣的。还有用于取消、暂停和继续的事件,您可能还希望实现这些事件来隐藏和显示您的 UI。

关于ios - AVSpeechSynthesizer - 如果 AVSpeechSynthesizer 正在说话并且已经停止说话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com