首页 > 代码库 > [iOS]AVSpeechSynthesizer语音合成

[iOS]AVSpeechSynthesizer语音合成

 1 #import <AVFoundation/AVFoundation.h>
 2 
 3 // 初始化方法
 4 AVSpeechSynthesizer *speech = [[AVSpeechSynthesizer alloc]init];
 5 
 6 // 设置内容
 7 AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:
 8                                 @"红鲤鱼与绿鲤鱼与驴"];
 9 // 设置语音类型
10 utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
11 
12 // 语速
13 utterance.rate = 0.5;
14 
15 // 开始朗读
16 [speech speakUtterance:utterance];

 

[iOS]AVSpeechSynthesizer语音合成