首先下载好百度语音的SDK,然后导入项目中,在把库导入
系统库
在导入SDK的时候要注意
1
注意事项2
注意事项3
注意事项4
注意事项注意这些没问题了我们就在controller中
代码如下:
ViewController.m// 百度语言环境//// Created by wzx on 17/8/4.// Copyright © 2017年 wzx. All rights reserved.//#import "ViewController.h"#import "BDRecognizerViewController.h"#import "BDRecognizerViewDelegate.h"#import "BDVRFileRecognizer.h"@interface ViewController (){
BDRecognizerViewController *bdrv;
NSMutableData *allData;
BDRecognizerViewParamsObject *bdvp;
UITextField *tf;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
b.frame = CGRectMake(100, 200, 100, 30);
[b setTitle:@"click" forState:UIControlStateNormal];
[b addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:b];
tf = [[UITextField alloc]initWithFrame:CGRectMake(100, 400, 200, 30)];
tf.borderStyle = UITextBorderStyleRoundedRect;
tf.layer.borderColor = [UIColor blackColor].CGColor;
[self.view addSubview:tf];
//主题设置
BDTheme *me = [BDTheme darkRedTheme];
bdrv = [[BDRecognizerViewController alloc]initWithOrigin:CGPointMake(20, 180) withTheme:me];
//全屏
bdrv.enableFullScreenMode = YES;
bdrv.delegate = self;
bdvp = [[BDRecognizerViewParamsObject alloc]init];
bdvp.apiKey = @"fxapkwi4V5hSCNTAHaY8BNtG";
bdvp.secretKey = @"bfdde8647f1b9ba3dbc287a479e70122";
}
-(void)click
{
allData = [[NSMutableData alloc]init];
[bdrv startWithParams:bdvp];
}
/**
* @brief 录音数据返回
*
* @param recordData 录音数据
* @param sampleRate 采样率
*/
- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate
{
[allData appendData:recordData];
}
//中间识别的结果
- (void)onPartialResults:(NSString *)results
{
tf.text = results;
}
@end
网友评论