问题
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