AVSpeechSynthesizer

2018-02-07  本文已影响55人  BoomLee

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];
上一篇 下一篇

猜你喜欢

热点阅读