美文网首页
AVSpeechSynthesizer

AVSpeechSynthesizer

作者: BoomLee | 来源:发表于2018-02-07 16:10 被阅读55次

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];

相关文章

网友评论

      本文标题:AVSpeechSynthesizer

      本文链接:https://www.haomeiwen.com/subject/tzcazxtx.html