欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

IOS百度语音与二维码的生成实例教程

程序员文章站 2022-05-01 17:35:55
一. 我们这里需要用到两个第三方 baidu-voice-sdk-ios-1.6(百度语音)、libqrencode(二维码生成) 二. 在info.plist设置允许访问网络 添加app tran...

一. 我们这里需要用到两个第三方 baidu-voice-sdk-ios-1.6(百度语音)、libqrencode(二维码生成)

二. 在info.plist设置允许访问网络 添加app transport security settings 在他的下面再添加nsallowsarbitraryloads并把后面的no改为yes

三. 导入以下依赖库

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 "viewcontroller.h"

#import "bdrecognizerviewcontroller.h"

#import "bdrecognizerviewdelegate.h"

#import "bdvoicerecognitionclient.h"

#import "qrcodegenerator.h"



@interface viewcontroller ()<bdrecognizerviewdelegate>





@property(nonatomic,strong)bdrecognizerviewcontroller *bdvc; //语音界面

@property(nonatomic,strong)nsmutabledata *alldata;

@property(nonatomic,strong)bdrecognizerviewparamsobject *bdvp; //参数设置 key 秘





// 创建显示二维码和内容的属性

@property (weak, nonatomic) iboutlet uiimageview *image;

@property (weak, nonatomic) iboutlet uilabel *lable;



@end



@implementation viewcontroller



- (void)viewdidload {

    [super viewdidload];

    // 使用百度主题设置

    bdtheme *me = [bdtheme lightorangetheme];

    self.bdvc = [[bdrecognizerviewcontrolleralloc]initwithorigin:cgpointmake(20, 10) withtheme:me];

    // 设置为全屏幕

   self.bdvc.enablefullscreenmode = yes;

    // 设置代理

    self.bdvc.delegate = self;

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

    // 设置appkey

    self.bdvp.apikey = @"anqlqinhgf2tl0gvp5xhncxm";

    self.bdvp.secretkey = @"c3d5f5f8ac5478e87802431389b2cba7";

}

// 识别语音

- (void)onrecorddataarrived:(nsdata *)recorddata samplerate:(int)samplerate{

    [self.alldata appenddata:recorddata];

}

// 把识别到的内容添加到lable上

- (void)onpartialresults:(nsstring *)results

{

    self.lable.text = results;

}

// 语音识别按钮 点击开始识别

- (ibaction)yuyinbutton:(id)sender {

    self.alldata = [[nsmutabledata alloc]init];

    [self.bdvc startwithparams:self.bdvp];

}

// 生成二维码按钮

- (ibaction)buttton:(id)sender {

    // 生成二维码按钮

     uiimage *img = [qrcodegenerator qrimageforstring:self.lable.textimagesize:self.image.frame.size.width];

    self.image.image = img;

}

// 清空内容

- (ibaction)clearbutton:(id)sender {

    self.lable.text = nil;



}







@end