IOS百度语音集成与二维码

SDK名称

Baidu-Voice-SDK-iOS-1.6

libqrencode

一.导入依赖库

GLKit.framework

CoreTelephony.framework

AVFoundation.framework

SystemConfiguration.framework

AudioToolbox.framework

libz.tbd

Security.framework

QuartzCore.framework

CoreText.framework

CoreLocation.framework

CFNetwork.framework

CoreGraphics.framework

二.导入头文件

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "QRCodeGenerator.h"

在编写程序的过程中,即使编译通过,但是在运行的过程中,偶尔会有类似 unrecognized selector sent to instance 的错误,为了避免该错误,需要到 target -> Build Settings 中修改 Other Linker Flags 的值,将其设置为 -ObjC,该值意在将静态库中所有的Objective-C 类和分类都加载到最后的可执行文件中。

另外,Other Linker Flags 还可以设置其他的值:

-all_load 会将库中所有的的目标文件都加入到可执行文件中,这样做会导致一个问题,如果引用了两个静态库,而这两个静态库恰好都引用了同一个第三发库,那么会报重复定义的错误 duplicate symbol。

-force_load 该值与 -all_load 相同,只是其后面需要指定具体要全部加载的库的路径,而其他库仍按需加载。


Info.plist

@interface ViewController (){

    //语音界面

        BDRecognizerViewController *bdrv;

        NSMutableData *allData;

        //参数设置 key 秘钥

        BDRecognizerViewParamsObject *bdvp;

        UILabel *label;

        UIImageView *imgV;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    BDTheme *me = [BDTheme lightGreenTheme];

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

    bdrv.enableFullScreenMode = YES;

    bdrv.delegate = self;

    bdvp = [[BDRecognizerViewParamsObject alloc]init];

    bdvp.apiKey = @"ANQLQINhgf2TL0gVP5xhNCxm";

    bdvp.secretKey = @"c3d5f5f8ac5478e87802431389b2cba7";

    // 创建图片框

    imgV= [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-100,380,200,200)];

    // 添加到主界面

    [self.view addSubview:imgV];

    //初始化label

    [self label];

}

-(void)label

{

    label = [[UILabel alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 100)];

    [self.view addSubview:label];

}

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

{

    [allData appendData:recordData];

}

- (void)onPartialResults:(NSString*)results

{

    label.text= results;

}

- (IBAction)start:(id)sender {

    allData = [[NSMutableData alloc]init];

    [bdrv startWithParams:bdvp];

}

- (IBAction)clear:(id)sender {

    label.text=nil;

}

- (IBAction)sheng:(id)sender {

    // 生成二维码

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

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

    imgV.image= img;

}

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