iOS 百度语音+二维码生成

之前还需要导入的第三方库有 libqrencode  、 Baidu-Voice-SDK-iOS-1


#import "ViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDRecognizerViewController.h"

#import "JSONKit.h"

#import "BDVoiceRecognitionClient.h"

#import "BDVRFileRecognizer.h"

#import "BDVRRawDataRecognizer.h"

#import "QRCodeGenerator.h"

@interface ViewController (){

 BDRecognizerViewController *bdrv; 

 NSMutableData *alldata;

 BDRecognizerViewParamsObject *bdvp; 

 UITextView *TextView;

}

@end

@implementation ViewController

- (void)viewDidLoad {

 [super viewDidLoad]; 

 TextView = [[UITextView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-350)/2, self.view.frame.size.height-600, 350, 150)];

 TextView.backgroundColor = [UIColor blackColor]; TextView.layer.cornerRadius = 8;

 TextView.layer.masksToBounds = YES; TextView.textColor = [UIColor orangeColor];

 TextView.font = [UIFont systemFontOfSize:18]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width-150)/2, self.view.frame.size.height-400, 150, 44)]; 

 btn.backgroundColor = [UIColor blackColor];

 [btn setTitle:@"语音识别" forState:0]; 

 [btn setTitleColor:[UIColor redColor] forState:0];

 btn.titleLabel.font = [UIFont systemFontOfSize:22];

 btn.layer.cornerRadius = 8;

 btn.layer.masksToBounds = YES; 

 [btn addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];

 [self.view addSubview:TextView]; [self.view addSubview:btn]; 

 BDTheme *me = [BDTheme lightRedTheme];

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

 bdrv.enableFullScreenMode = YES;

 bdrv.delegate = self;

 bdvp = [[BDRecognizerViewParamsObject alloc] init]; 

 bdvp.apiKey = @"TT49YpLnc0Wk8PqdxhimHcZg"; 

 bdvp.secretKey = @"f790c0bfc23974d19ed50d23c6745299";

}

-(void)add{ alldata = [[NSMutableData alloc] init];

 [bdrv startWithParams:bdvp];

}

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

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

 UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height-300, 200, 200)];

 image.image = [QRCodeGenerator qrImageForString:[[[[aResults lastObject] lastObject] allKeys] lastObject] imageSize:self.view.frame.size.width];

 [self.view addSubview:image];

 }

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    [TextView resignFirstResponder];

}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值