IOS百度语音与二维码生成

本文介绍如何在iOS应用中集成百度语音识别SDK和使用libqrencode库生成二维码。首先,需要引入相关框架和设置info.plist以允许网络访问。接着,创建并配置BDRecognizerViewController以实现语音识别,并监听识别结果更新标签内容。同时,提供一个生成二维码的功能,将标签文本转化为二维码图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


一.  我们这里需要用到两个第三方  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 (weaknonatomicIBOutlet UIImageView *image;

@property (weaknonatomicIBOutlet UILabel *lable;


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // 使用百度主题设置

    BDTheme *me = [BDTheme lightOrangeTheme];

    self.bdvc = [[BDRecognizerViewControlleralloc]initWithOrigin:CGPointMake(2010withTheme: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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值