首页 > 其他 > 详细

AVFoundation 文本播报

时间:2017-08-29 18:29:00      阅读:238      评论:0      收藏:0      [点我收藏+]

 

#import <Foundation/Foundation.h>

#import <AVFoundation/AVFoundation.h>

 

@interface Speaker : NSObject

 

@property(nonatomic,strong)AVSpeechSynthesizer *synthesizer;

 

+ (instancetype)speechcontroller;

 

- (void)beginConversation;

 

@end

 

///

#import "Speaker.h"

 

@interface Speaker ()

 

@property(nonatomic,strong)NSArray *voices;

@property(nonatomic,strong)NSArray *speechStrings;

 

@end

 

@implementation Speaker

 

 

+ (instancetype)speechcontroller{

    return [[self alloc]init];

}

- (instancetype)init

{

    self = [super init];

    if (self) {

        _synthesizer = [[AVSpeechSynthesizer alloc]init];

        

      //zh-CN 中文  en-US 英文

        _voices = @[[AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"],

//                    [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"]

                    ];

        

        _speechStrings = @[@"hello world",

                           @"文本播报",

                           @"very good"

                           ];

    }

    return self;

}

 

 

 

- (void)beginConversation{

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

        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:self.speechStrings[i]];

        utterance.voice = self.voices[0];//设置声音

        utterance.rate = 0.4f;//播放语音内容的速度

        utterance.pitchMultiplier = 0.7f;//语调

        utterance.postUtteranceDelay = 0.1f;//在说下一句话前的停顿时长

        //开始语音播放

        [self.synthesizer speakUtterance:utterance];

        

    }

    

}

AVFoundation 文本播报

原文:http://www.cnblogs.com/daxueshan/p/7449684.html

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