iOS 7之后,苹果新增了一个简单的 API ---- AVSpeechSynthesizer 来实现语音播报功能。
第一步:导入 AVFoundation/AVFoundation.h 系统库
#import <AVFoundation/AVFoundation.h>
第二步:设置播报参数
//初始化语音播报
AVSpeechSynthesizer * av = [[AVSpeechSynthesizer alloc]init];
//设置播报的内容
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc]initWithString:@"语音播报"];
//设置语言类别
AVSpeechSynthesisVoice * voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
utterance.voice = voiceType;
//设置播报语速
utterance.rate = 0.5;
[av speakUtterance:utterance];
参考文章:http://blog.csdn.net/m372897500/article/details/30069967
网友评论