1.添加类库AVFoundation.framework
2.引入
#import <AVFoundation/AVFoundation.h>
3.定义属性
@property (nonatomic,strong) AVSpeechSynthesizer *spee;
4.对其进行懒加载操作,并引入协议 < AVSpeechSynthesizerDelegate >
-(AVSpeechSynthesizer *)spee{
if (!_spee) {
_spee = [AVSpeechSynthesizer new];
_spee.delegate = self;
}
return _spee;
}
5.转化为语音
AVSpeechUtterance *utt = [[AVSpeechUtterance alloc]initWithString:@“填写读取的内容”];
utt.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh_CN"];
[self.spee speakUtterance:utt];