Add audio to Map on iOS

假装没事ソ 提交于 2019-12-25 04:26:34

问题


I have a map right now with several points on it that are quite close to each other. Right now when a user taps the annotation a little pop up occurs with the location name on it. How could I have it so that a piece of audio about that location plays?

I'm not too fussed about pause buttons etc yet, right now I want to know how I'd implement audio into this!


回答1:


Use AVSpeechSynthesizer

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Some random text that you want to be spoken"];
[utterance setRate:0.7];
[synthesizer speakUtterance:utterance];

http://jonathanfield.me/avspeechsynthesizer-ios-text-speech-ios-7/

Text to speech conversion

UPDATE:

Add delegate to your MKMapView. For example it could be self

self.mapView.delegate = self;

(self should confirm to MKMapViewDelegate). And implement delegate's method

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)anView
{
    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:anView.annotation.title];
    [utterance setRate:0.7];
    [synthesizer speakUtterance:utterance];
}


来源:https://stackoverflow.com/questions/22426464/add-audio-to-map-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!