首先是头文件
#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];
}
网友评论