需要導入<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];