AVSpeechSynthesizer 语音合成器

来源:互联网 发布:田岛绣花软件9.0 编辑:程序博客网 时间:2024/05/22 05:25

NSArray *speechStrings = 

@[@"Hello AV Foundation. How are you?",

             @"I'm well! Thanks for asking.",

             @"Are you excited about the book?",

             @"Very! I have always felt so misunderstood.",

             @"What's your favorite feature?",

             @"Oh, they're all my babies.  I couldn't possibly choose.",

             @"It was great to speak with you!",

             @"The pleasure was all mine!  Have fun!"];


AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizeralloc] init];

for (NSUInteger i =0; i < speechStrings.count; i++) {

       AVSpeechUtterance *utterance =  [[AVSpeechUtterancealloc] initWithString:speechStrings[i]];

        utterance.voice = [AVSpeechSynthesisVoicevoiceWithLanguage:@"en-US"];//设置使用什么语言播放

        utterance.rate =1.0f; //设置语音内容的速度0-1

        utterance.pitchMultiplier =0.8f; //改变合成声音的音调

        utterance.postUtteranceDelay =1; //目的是让语音合成器播放下一语句前又短暂的暂停

        [synthesizerspeakUtterance:utterance]; 

}



0 0
原创粉丝点击