码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-文本转语音

时间:2017-08-17 23:32:30      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:sar   nsarray   vsp   size   ice   直接   间隔   tip   速度   

iOS提供了一个类AVSpeechSynthesizer来实现文本到语音的功能, 即读出文字

直接上代码:

    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
    
    NSArray *speechStrings = @[@"Hello AV Foundation. How are you?",
                               @"我很好, 感谢!",
                               @"Are you excited about the book?",
                               @"是的, 我非常喜欢这本书.",
                               @"What‘s your favourite feature?",
                               @"我都很喜欢呢!",
                               @"It was great to speak with you!",
                               @"我也是, 祝你愉快"];
    
    NSArray *voices = @[[AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"],
                        [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-cn"]];
    
    
    for (int i = 0; i < speechStrings.count; i ++) {
        
        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:speechStrings[i]];
        
        utterance.voice              = voices[i % 2];   // 语言
        utterance.rate               = 0.4f;            // 播放语音的速度
        utterance.pitchMultiplier    = 0.8f;            // 音调
        utterance.postUtteranceDelay = 0.1f;            // 下一句间隔时间
        
        // 发音
        [synthesizer speakUtterance:utterance];
    }

 

iOS-文本转语音

标签:sar   nsarray   vsp   size   ice   直接   间隔   tip   速度   

原文地址:http://www.cnblogs.com/zhouxihi/p/7384886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!