关于百度语音二维码的使用方法

#import "ViewController.h"
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "QRCodeGenerator.h"
@interface ViewController ()
{
 BDRecognizerViewController *bdrv;
 NSMutableData *allData;
 BDRecognizerViewParamsObject *bdvp;
 UILabel *label;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    // Do any additional setup after loading the view, typically from a nib.
   
    //Lable初始化
   
    label = [[UILabel alloc]initWithFrame:CGRectMake(50,100,300, 50)];
   
    label.backgroundColor = [UIColor blueColor];
   
    [self.view addSubview:label];
   
    //这里用一个button来实现
   
    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   
    b.frame = CGRectMake(100, 400, 100, 30);
   
    [b setTitle:@"click" forState:UIControlStateNormal];
   
    [b addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
   
    [self.view addSubview:b];
   
    //主题设置
   
    BDTheme *me = [BDTheme lightGreenTheme];
   
    bdrv = [[BDRecognizerViewController alloc]initWithOrigin:CGPointMake(20, 180) withTheme:me];
   
    //全屏幕
   
    bdrv.enableFullScreenMode = YES;
   
    bdrv.delegate = self;
   
    bdvp = [[BDRecognizerViewParamsObject alloc]init];
   
    //bdvp.productID 不用设置
   
    bdvp.apiKey = @"ANQLQINhgf2TL0gVP5xhNCxm";
   
    bdvp.secretKey = @"c3d5f5f8ac5478e87802431389b2cba7";
   
}

//button方法

-(void)click{
   
    allData = [[NSMutableData alloc]init];
   
    [bdrv startWithParams:bdvp];
   
}

/**
 
 * @brief 录音数据返回
 
 * @param recordData 录音数据
 
 * @param sampleRate 采样率
 
 */

- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate{
   
    [allData appendData:recordData];
   
}

//此方法是将语音传递到lable上

- (void)onPartialResults:(NSString *)results

{
   
    label.text = results;
   
}

-(void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults{
    label.text=[[[[aResults lastObject]lastObject]allKeys]lastObject];
   
    UIImageView * img =[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 150, 150)];
    img.image=[QRCodeGenerator qrImageForString:[[[[aResults lastObject]lastObject]allKeys]lastObject] imageSize:self.view.frame.size.width];
    [self.view addSubview:img];
    [self.view reloadInputViews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end


值得注意的是。百度语音需要导入几个类库。不然的话容易报错

关于百度语音二维码的使用方法_第1张图片

你可能感兴趣的:(关于百度语音二维码的使用方法)