iOS 百度語音+二維碼生成

之前還需要導(dǎo)入的第三方庫有?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:@"語音識(shí)別" 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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容