關于百度語音二維碼的使用方法

#import "ViewController.h"
#import "BDRecognizerViewController.h"
#import "BDRecognizerViewDelegate.h"
#import "BDVoiceRecognitionClient.h"
#import "QRCodeGenerator.h"
@interface ViewController ()<BDRecognizerViewDelegate>
{
?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來實現(xiàn)
???
??? 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 錄音數(shù)據(jù)返回
?
?* @param recordData 錄音數(shù)據(jù)
?
?* @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


值得注意的是。百度語音需要導入幾個類庫。不然的話容易報錯

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

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

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