美文网首页
iOS百度语音环境

iOS百度语音环境

作者: 往日的时光 | 来源:发表于2017-08-31 19:52 被阅读0次

    首先下载好百度语音的SDK,然后导入项目中,在把库导入


    系统库

    在导入SDK的时候要注意

    1

    注意事项

    2

    注意事项

    3

    注意事项

    4

    注意事项

    注意这些没问题了我们就在controller中


    代码如下:

    ViewController.m//  百度语言环境////  Created by wzx on 17/8/4.//  Copyright © 2017年 wzx. All rights reserved.//#import "ViewController.h"#import "BDRecognizerViewController.h"#import "BDRecognizerViewDelegate.h"#import "BDVRFileRecognizer.h"@interface ViewController (){

    BDRecognizerViewController *bdrv;

    NSMutableData *allData;

    BDRecognizerViewParamsObject *bdvp;

    UITextField *tf;

    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {

    [super viewDidLoad];

    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    b.frame = CGRectMake(100, 200, 100, 30);

    [b setTitle:@"click" forState:UIControlStateNormal];

    [b addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:b];

    tf = [[UITextField alloc]initWithFrame:CGRectMake(100, 400, 200, 30)];

    tf.borderStyle = UITextBorderStyleRoundedRect;

    tf.layer.borderColor = [UIColor blackColor].CGColor;

    [self.view addSubview:tf];

    //主题设置

    BDTheme *me = [BDTheme darkRedTheme];

    bdrv = [[BDRecognizerViewController alloc]initWithOrigin:CGPointMake(20, 180) withTheme:me];

    //全屏

    bdrv.enableFullScreenMode = YES;

    bdrv.delegate = self;

    bdvp = [[BDRecognizerViewParamsObject alloc]init];

    bdvp.apiKey = @"fxapkwi4V5hSCNTAHaY8BNtG";

    bdvp.secretKey = @"bfdde8647f1b9ba3dbc287a479e70122";

    }

    -(void)click

    {

    allData = [[NSMutableData alloc]init];

    [bdrv startWithParams:bdvp];

    }

    /**

    * @brief 录音数据返回

    *

    * @param recordData 录音数据

    * @param sampleRate 采样率

    */

    - (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate

    {

    [allData appendData:recordData];

    }

    //中间识别的结果

    - (void)onPartialResults:(NSString *)results

    {

    tf.text = results;

    }

    @end

    相关文章

      网友评论

          本文标题:iOS百度语音环境

          本文链接:https://www.haomeiwen.com/subject/rdaydxtx.html