一、接入指南
先引入编译需要的Framework:
AudioToolbox.framework
AVFoundation.framework
SystemConfiguration.framework
CoreTelephony.framework
Security.framework
libz.1.tbd
CFNetwork.framework
CoreLocation.framework
OpenGLES.framework
QuartzCore.framework
GLKit.framework
CoreGraphics.framework
CoreText.framework
二、导入Baidu-Voice-SDK-iOS-1
1.其中BDVoiceRecognitionClientResources为蓝色
2.导入JSONKit.h和JSONKit.m文件
3.Build Phases中JSONKit.m添加-fno-objc-arc
三、在ViewController中
1、导入头文件
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "BDVRRawDataRecognizer.h"
#import "BDVRFileRecognizer.h"
2、添加协议BDRecognizerViewDelegate
@interface ViewController (){
BDRecognizerViewController *bdv;
//参数设置 key 秘钥
BDRecognizerViewParamsObject *bdf;
NSMutableData *allData;
}
3、在- (void)viewDidLoad显示
//设置主题样式
BDTheme *theme = [BDTheme lightOrangeTheme];
// 创建识别控件
bdv = [[BDRecognizerViewController alloc] initWithOrigin:CGPointMake(9, 128) withTheme:theme];
// 全屏UI
bdv.enableFullScreenMode = YES;
// 设置委托
bdv.delegate = self;
bdf = [[BDRecognizerViewParamsObject alloc]init];
//bdf.productID 不用设置
bdf.apiKey = @"ANQLQINhgf2TL0gVP5xhNCxm";
bdf.secretKey = @"c3d5f5f8ac5478e87802431389b2cba7";
3、按钮
- (IBAction)BByy:(id)sender {
allData = [[NSMutableData alloc]init];
[bdv startWithParams:bdf];
}
4、协议中的方法
/**
* @brief 语音识别结果返回,搜索和输入模式结果返回的结构不相同
*
* @param aBDRecognizerView 弹窗UI
* @param aResults 返回结果,搜索结果为数组,输入结果也为数组,但元素为字典
*/
- (void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults{
NSLog(@"==2======%@",[[[[aResults lastObject]lastObject] allKeys] lastObject] );
self.textIF.text =[[[[aResults lastObject]lastObject] allKeys] lastObject];
}
/**
* @brief 录音数据返回
*
* @param recordData 录音数据
* @param sampleRate 采样率
*/
- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate{
[allData appendData:recordData];
}