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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 4,243评论 0 3
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 9,187评论 2 7
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 5,861评论 0 3
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 5,265评论 0 3
  • 《临摹达芬奇画像》: 又斗胆临摹一位奇才大家,画得小心翼翼。 达芬奇可是世界历史上赫赫有名的人物,声名远播,大大超...
    雪盈禅心阅读 5,366评论 3 0