AVSpeechSynthesizer

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];
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容