#import "ViewController.h"
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "BDVRRawDataRecognizer.h"
#import "BDVRFileRecognizer.h"
@interface ViewController ()
{
BDRecognizerViewController *bdrv;
NSMutableData *alldata;
BDRecognizerViewParamsObject *bdvp;
UILabel *label ;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
label = [[UILabel alloc]initWithFrame:CGRectMake(0, 44, 300, 200)];
label.backgroundColor = [UIColor yellowColor];
[self.view addSubview:label];
UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
b.frame = CGRectMake(100, 400, 100, 30);
[b setTitle:@"点击" 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.apiKey = @"eSr6i3gzPHrdtvq8TNlVd246";
bdvp.secretKey = @"501aa5c87aec04a5b31ed3fee6b83e8c";
}
-(void)click{
alldata = [[NSMutableData alloc]init];
[bdrv startWithParams:bdvp];
}
/**
* @brief 语音识别结果返回,搜索和输入模式结果返回的结构不相同
*
* @param aBDRecognizerView 弹窗UI
* @param aResults 返回结果,搜索结果为数组,输入结果也为数组,但元素为字典
*/
- (void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults{
// NSDictionary *dic =[aResults lastObject];
//结果显示在label上。。。。
NSLog(@"==2======%@",[[[[aResults lastObject]lastObject] allKeys] lastObject] );
label.text =[[[[aResults lastObject]lastObject] allKeys] lastObject];
}
/**
* @brief 录音数据返回
*
* @param recordData 录音数据
* @param sampleRate 采样率
*/
- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate{
[alldata appendData:recordData];
NSLog(@"====%@",[NSJSONSerialization JSONObjectWithData:recordData options:0 error:nil]);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
网友评论