最近在弄文字转语音的东西,IOS6以前的话基本是用私用api或者请求第三方的语音包,IOS7之后有了AVSpeechSynthesizer可以使用,记录下。
使用前先导入
#import <AVFoundation/AVFoundation.h>
下面是我自己用的方法
/**
* 调用系统朗读text
*
* @param text 需要朗读的文字
*/
- (void)readText:(NSString *)text{
if( ([[[UIDevice currentDevice] systemVersion] doubleValue] < 7.0)){
return;
}
_AVsynthesize = [[AVSpeechSynthesizer alloc]init];
_AVsynthesize.delegate = self;
AVSpeechUtterance * utt = [[AVSpeechUtterance alloc] initWithString:text];
AVSpeechSynthesisVoice * type = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
utt.voice = type;
utt.rate = 0.1;
[_AVsynthesize speakUtterance:utt];
MYLog(@"read.isSpeaking = %hhd",_AVsynthesize.isSpeaking);
/*