百度语音实现代码

首先是头文件


#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "BDVRRawDataRecognizer.h"

#import "BDVRFileRecognizer.h"

然后是代理以及全局变量

<BDRecognizerViewDelegate>

{

//语音界面

BDRecognizerViewController *bdrv;

NSMutableData *allData;

//参数设置 key 秘钥

BDRecognizerViewParamsObject *bdvp;

}

然后是viewdidload里

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";

最后是两个方法

-(void)click{

allData = [[NSMutableData alloc]init];

[bdrv startWithParams:bdvp];

}

/**

* @brief 录音数据返回

*

* @param recordData 录音数据

* @param sampleRate 采样率

*/

- (void)onRecordDataArrived:(NSData *)recordData sampleRate:(int)sampleRate{

[allData appendData:recordData];

}

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

相关阅读更多精彩内容

友情链接更多精彩内容