gpt4 book ai didi

ios - AVSpeechSynthesizer 的暂停按钮

转载 作者:行者123 更新时间:2023-11-29 03:08:41 25 4
gpt4 key购买 nike

目前我有一张带有注释的 map ,当用户点击注释时会播放音频。我想添加一个播放/暂停按钮,但它不起作用,我不确定为什么。

AVSpeechSynthesizer

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)anView
{
//Get a reference to the annotation this view is for...
id<MKAnnotation> annSelected = anView.annotation;

//Before casting, make sure this annotation is our custom type
//(and not some other type like MKUserLocation)...
if ([annSelected isKindOfClass:[MapViewAnnotation class]])
{
MapViewAnnotation *mva = (MapViewAnnotation *)annSelected;

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];

AVSpeechUtterance *utterance =
[AVSpeechUtterance speechUtteranceWithString:mva.desc];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-gb"];

[utterance setRate:0.35];
[synthesizer speakUtterance:utterance];
}

按钮

- (IBAction)pauseButtonPressed:(UIButton *)sender 
{
[_synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];

}

现在当我点击它时没有任何反应。

最佳答案

use this one for pause

- (IBAction)pausePlayButton:(id)sender
{
if([synthesize isSpeaking]) {
[synthesize pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@""];
[synthesize speakUtterance:utterance];
[synthesize pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}

}

关于ios - AVSpeechSynthesizer 的暂停按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22462203/

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