#import "ViewController.h"
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "BDVRRawDataRecognizer.h"
#import "BDVRFileRecognizer.h"
@interfaceViewController ()
{
? ? BDRecognizerViewController *bdvc;
? ? NSMutableData *Mdata;
? ? BDRecognizerViewParamsObject *bdvp;
? ? UITextView *textV;
}
@end
@implementation ViewController
- (void)viewDidLoad {
? ? [superviewDidLoad];
? ? UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ? button.frame = CGRectMake(100,100,100,30);
? ? button.backgroundColor = [UIColor lightGrayColor];
? ? button.layer.cornerRadius =10;
? ? [button setTitle:@"點(diǎn)擊說話"forState:UIControlStateNormal];
? ? [button addTarget:selfaction:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
? ? [self.view addSubview:button];
? ? BDTheme *me = [BDTheme lightBlueTheme];
? ? //初始化
? ? bdvc = [[BDRecognizerViewController alloc] initWithOrigin:CGPointMake(20,100) withTheme:me];
? ? //設(shè)置代理
? ? bdvc.delegate =self;
? ? //全屏
? ? bdvc.enableFullScreenMode =YES;
? ? bdvp = [[BDRecognizerViewParamsObject alloc] init];
? ? bdvp.apiKey =@"S0UrbTi31Yi6hTGjssCk0hzR";
? ? bdvp.secretKey =@"adb44d9f61aa57d86bcf970572c2f568";
? ? //初始化文本框
? ? textV = [[UITextView alloc] initWithFrame:CGRectMake(100,200,200,200)];
? ? textV.layer.borderWidth =1;
? ? [self.view addSubview:textV];
}
- (void)clickButton
{
? ? Mdata = [[NSMutableData alloc] init];
? ? [bdvc startWithParams:bdvp];
}
#pragma mark -- 代理方法
/**
?* @brief 語音識(shí)別結(jié)果返回,搜索和輸入模式結(jié)果返回的結(jié)構(gòu)不相同
?*
?* @param aBDRecognizerView 彈窗UI
?* @param aResults 返回結(jié)果,搜索結(jié)果為數(shù)組,輸入結(jié)果也為數(shù)組,但元素為字典
?*/
- (void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults
{
? ? textV.text = [[[[aResults objectAtIndex:0]objectAtIndex:0]allKeys]objectAtIndex:0];
}
/**
?* @brief 錄音數(shù)據(jù)返回
?*
?* @param recordData 錄音數(shù)據(jù)
?* @param sampleRate 采樣率
?*/
- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate
{
? ? //拼接
? ? [Mdata appendData:recordData];
}
@end

