百度语音API的使用

2017-12-21  本文已影响0人  __DREAM

//导入头文件

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "BDVRRawDataRecognizer.h"

#import "BDVRFileRecognizer.h"

#import "JSONKit.h"

//JSONKit关闭ARC

-fno-objc-arc

//添加库

libc++.tbd , libz.1.2.5.tbd , AudioToolbox.framework , AVFoundation.framework , CFNetwork.framework , CoreLocation.framework , CoreTelephony.framework , SystemConfiguration.framework , GLKit.framework

//遵守 BDRecognizerViewDelegate 的协议

//定义一些属性

BDRecognizerViewController *bdrv;

BDRecognizerViewParamsObject *bdvp;

UILabel *label;//请自行初始化

UIButton *button;//请自行初始化

/在 viewDidLoad 中将API初始化并使用

BDTheme *me = [BDTheme lightRedTheme];

bdrv = [[BDRecognizerViewController alloc]initWithOrigin:CGPointMake(20, 100) withTheme:me];

bdrv.enableFullScreenMode = YES;

bdrv.delegate = self;

bdvp = [[BDRecognizerViewParamsObject alloc]init];

bdvp.apiKey = @"pgk2mk3AZl2Uz5y6cydQTmDR";

bdvp.secretKey = @"62c14997cf54b83c94fad2f93d8bc88b";

//在按钮点击事件中

[bdrv startWithParams:bdvp];

//调用 BDRecognizerViewDelegate代理中的方法

//语音识别结果返回

-(void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults{

//将获取的文字添加到文本控件上

_label.text = [[[[aResults lastObject]lastObject]allKeys]lastObject];

}

//录音数据返回

-(void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate{

}

//录音结束

- (void)onRecordEnded{

}

上一篇下一篇

猜你喜欢

热点阅读