需要导入<AVFoundatian/AVFoundtian.h>
AVSpeechSynthesizer * synthsizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc] initWithString:@"aosika先生"];//需要转换的文本
//设置语言类别(不能被识别,返回值为nil)@"zh-CN"国语@"zh-HK"粤语@"zh-TW"台湾
//self.voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
//self.utterance.voice = self.voiceType;
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];//国家语言
//设置语速快慢
utterance.rate = 0.4f;//声速
[synthsizer speakUtterance:utterance];
初始化AVSpeechSynthesizer 在初始化 AVSpeechUtterance
开始播报[synthsizer speakUtterance:utterance];
停止播放 [synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];