- 在工程中 option+command+n 创建一个文件夹命名为 SDK
- 把SDK文件拖拽到 工程的SDK文件夹内 (124) (编译后会有18个报错)
- 关闭arc : 点击工程的第一个蓝文件(你的工程名) 然后依次点击 Build Phases -> Compile Soures -> JSONKit.m 添加 -fno-objc-arc (这个时候编译 , 没有报错)
- 打开网络请求
- 倒入类库 类库如下
libBDVoiceRecognitionClient.a (这个会自己就有)
libc++.tbd
libz.1.2.5.tbd
AudioToolbox.framework
AVFoundation.framework
CFNetwork.framework
CoreLocation.framework
CoreTelephony.framework
SystemConfiguration.framework
GLKit.framework - ViewController.m里面
#import "ViewController.h"
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "BDVRRawDataRecognizer.h"
#import "BDVRFileRecognizer.h"
@interface ViewController ()<BDRecognizerViewDelegate>
{
BDRecognizerViewController *bdvc;
NSMutableData *Mdata;
BDRecognizerViewParamsObject *bdvp;
UITextView *textV;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 100, 100, 30);
button.backgroundColor = [UIColor lightGrayColor];
button.layer.cornerRadius = 10;
[button setTitle:@"点击说话" forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
BDTheme *me = [BDTheme lightBlueTheme];
bdvc = [[BDRecognizerViewController alloc] initWithOrigin:CGPointMake(20, 100) withTheme:me];
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 语音识别结果返回,搜索和输入模式结果返回的结构不相同
*
* @param aBDRecognizerView 弹窗UI
* @param aResults 返回结果,搜索结果为数组,输入结果也为数组,但元素为字典
*/
- (void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults
{
textV.text = [[[[aResults objectAtIndex:0]objectAtIndex:0]allKeys]objectAtIndex:0];
}
/**
* @brief 录音数据返回
*
* @param recordData 录音数据
* @param sampleRate 采样率
*/
- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate
{
[Mdata appendData:recordData];
}
@end