AVFoundation
框架的语音合成类,可以将文字转化为语音。和Siri的发音一致。
@property (nonatomic, strong) AVSpeechSynthesizer *speechSynthesizer;
- (AVSpeechSynthesizer *)speechSynthesizer{
if (!_speechSynthesizer) {
_speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
_speechSynthesizer.delegate = self;
}
return _speechSynthesizer;
}
AVSpeechUtterance *speechUtterance = [AVSpeechUtterance speechUtteranceWithString:@"xxx"];
AVSpeechSynthesisVoice *speechSynthesisVoice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
speechUtterance.voice = speechSynthesisVoice;
//zh-HK,zh-TW,en-US,不同语言会发不同声音。
//NSLog(@"%@",[AVSpeechSynthesisVoice speechVoices]);
[self.speechSynthesizer speakUtterance:speechUtterance];
网友评论