IOS百度语音识别与二维码生成

下载SDK地址:点击下载百度语音识别SDK

导入依赖库:

GLKit.framework

CoreTelephony.framework

AVFoundation.framework

SystemConfiguration.framework

AudioToolbox.framework

libz.tbd

Security.framework

QuartzCore.framework

CoreText.framework

CoreLocation.framework

CFNetwork.framework

CoreGraphics.framework


在Build Setting中找到Other Linker Flags添加-ObjC


导入头文件:

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "QRCodeGenerator.h"

添加代理:

BDRecognizerViewDelegate

添加属性

//语音界面

@property (nonatomic , strong) BDRecognizerViewController *bdrv;

@property (nonatomic , strong) NSMutableData *allData;

//参数设置 key 秘钥

@property (nonatomic , strong)BDRecognizerViewParamsObject *bdvp;

//xib上的label

@property (weak, nonatomic) IBOutlet UILabel *label;

//xib上的uiimageView

@property (weak, nonatomic) IBOutlet UIImageView *imgV;

在viewDidLoad方法里加载

-(void)viewDidLoad

{

BDTheme *me = [BDTheme lightGreenTheme];

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


 self.bdrv.enableFullScreenMode = YES;


 self.bdrv.delegate = self;


 self.bdvp = [[BDRecognizerViewParamsObject alloc]init];


 self.bdvp.apiKey = @"ANQLQINhgf2TL0gVP5xhNCxm";


 self.bdvp.secretKey = @"c3d5f5f8ac5478e87802431389b2cba7";

}

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

 [self.allData appendData:recordData];

}

- (void)onPartialResults:(NSString *)results

{

 self.label.text = results;

}

以下是xib按钮生成的触发方法

开始识别语音

- (IBAction)shibie:(id)sender {

 self.allData = [[NSMutableData alloc]init];

 [self.bdrv startWithParams:self.bdvp];

}

将label上的文字清空

- (IBAction)clier:(id)sender {

 self.label.text = nil;

}

生成二维码

- (IBAction)sheng:(id)sender {

 // 生成二维码

 UIImage *img = [QRCodeGenerator qrImageForString:self.label.text        imageSize:self.imgV.frame.size.width];

 // 将生成的二维码赋值给图片框

 self.imgV.image = img;

}


你可能感兴趣的:(IOS百度语音识别与二维码生成)