美文网首页
百度语音实现代码

百度语音实现代码

作者: 1073d142fdd4 | 来源:发表于2017-05-11 08:01 被阅读0次

    首先是头文件

    #import "BDRecognizerViewController.h"

    #import "BDRecognizerViewDelegate.h"

    #import "BDVoiceRecognitionClient.h"

    #import "BDVRRawDataRecognizer.h"

    #import "BDVRFileRecognizer.h"

    然后是代理以及全局变量

    <BDRecognizerViewDelegate>

    {

    //语音界面

    BDRecognizerViewController *bdrv;

    NSMutableData *allData;

    //参数设置 key 秘钥

    BDRecognizerViewParamsObject *bdvp;

    }

    然后是viewdidload里

    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];

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

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

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

    [self.view addSubview:b];

    //主题设置

    BDTheme *me = [BDTheme lightGreenTheme];

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

    //全屏幕

    bdrv.enableFullScreenMode = YES;

    bdrv.delegate = self;

    bdvp = [[BDRecognizerViewParamsObject alloc]init];

    //bdvp.productID 不用设置

    bdvp.apiKey = @"ANQLQINhgf2TL0gVP5xhNCxm";

    bdvp.secretKey = @"c3d5f5f8ac5478e87802431389b2cba7";

    最后是两个方法

    -(void)click{

    allData = [[NSMutableData alloc]init];

    [bdrv startWithParams:bdvp];

    }

    /**

    * @brief 录音数据返回

    *

    * @param recordData 录音数据

    * @param sampleRate 采样率

    */

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

    [allData appendData:recordData];

    }

    相关文章

      网友评论

          本文标题:百度语音实现代码

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