iOS百度语音环境

首先下载好百度语音的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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容