目前我有一张带有注释的地图,当用户点击注释时,会播放音频。我想添加一个播放/暂停按钮,但它不起作用,我不确定为什么。
AVS语音合成器
- (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];
}
现在,当我单击它时,什么也没有发生。