美文网首页
iOS 文字转语音

iOS 文字转语音

作者: ShawnJiFreeMan | 来源:发表于2018-12-27 11:39 被阅读6次
#import <AVFoundation/AVFoundation.h>

- (void)readText(NSString *)txtContent{
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-TW"]; //en-US
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:txtContent];
    utterance.voice = voice;
    utterance.rate = ([UIDevice currentDevice].systemVersion.doubleValue>=9.0) ? 0.5 : 0.2; //0.4;
    //utterance.pitchMultiplier = 2.0;//语调 0.5-2.0
    AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
    [speechSynthesizer speakUtterance:utterance];
}

相关文章

网友评论

      本文标题:iOS 文字转语音

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