首页 > 移动平台 > 详细

iOS-文本转语音

时间:2017-08-17 23:18:41      阅读:319      评论:0      收藏:0      [点我收藏+]

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-文本转语音

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!