百度云语音合成

上篇介绍了百度云语音识别的功能,接下来开始实现百度云语音合成的功能。

接上篇:百度云语音识别

一,配置环境,导入依赖的库文件

二,

#import "BDSSpeechSynthesizer.h"

//遵循代理
@interface ViewController ()<BDSSpeechSynthesizerDelegate>
//初始化控件
@property(nonatomic,strong)UIButton *voiceSynthesisButton;
@property(nonatomic,strong) UITextView *textView;

self.voiceSynthesisButton = [[UIButton alloc]initWithFrame:CGRectMake(20, 150, 375, 40)];
    self.voiceSynthesisButton.backgroundColor = [UIColor redColor];
    [self.voiceSynthesisButton setTitle:@"开始语音合成" forState:UIControlStateNormal];
    [self.voiceSynthesisButton addTarget:self action:@selector(startSynthesis:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.voiceSynthesisButton];
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 220, 375,200)];
    textView.backgroundColor = [UIColor yellowColor];
    textView.font = [UIFont systemFontOfSize:17.0];
    [self.view addSubview:textView];
    self.textView = textView;

//初始化百度语音合成
- (BDSSpeechSynthesizer *)bdSpeech{

    if (!_bdSpeech) {
        //设置、获取日志级别
        [BDSSpeechSynthesizer setLogLevel:BDS_PUBLIC_LOG_VERBOSE];
        _bdSpeech = [BDSSpeechSynthesizer sharedInstance];
        //设置合成器代理
        [_bdSpeech setSynthesizerDelegate:self];
        //为在线合成设置认证信息
        [_bdSpeech setApiKey:API_KEY withSecretKey:SECRET_KEY];
        //设置语调
        [_bdSpeech setSynthParam:[NSNumber numberWithInt:4] forKey:BDS_SYNTHESIZER_PARAM_PITCH];
        //设置语速
        [_bdSpeech setSynthParam:[NSNumber numberWithInt:5] forKey:BDS_SYNTHESIZER_PARAM_SPEED];
    }
    return _bdSpeech;
}
- (void)startSynthesis:(UIButton *)btn{
    NSString *contentStr = self.textView.text;
    //朗读内容
    [self.bdSpeech speakSentence:contentStr withError:nil];
}

 

三,演示地址:百度云语音识别,合成   密码:ebpv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值