當前位置:名人名言大全網 - 短信平臺 - 百度語音API的使用

百度語音API的使用

//導入頭文件

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "BDVRRawDataRecognizer.h"

#import "BDVRFileRecognizer.h"

#import "JSONKit.h"

//JSONKit關閉ARC

-fno-objc-arc

//添加庫

libc++.tbd , libz.1.2.5.tbd ,?AudioToolbox.framework ,?AVFoundation.framework ,?CFNetwork.framework ,?CoreLocation.framework ,?CoreTelephony.framework ,?SystemConfiguration.framework ,?GLKit.framework

//遵守 BDRecognizerViewDelegate 的協議

//定義壹些屬性

BDRecognizerViewController *bdrv;

BDRecognizerViewParamsObject *bdvp;

UILabel *label;//請自行初始化

UIButton *button;//請自行初始化

/在?viewDidLoad 中將API初始化並使用

BDTheme *me = [BDTheme lightRedTheme];

bdrv = [[BDRecognizerViewController alloc]initWithOrigin:CGPointMake(20, 100) withTheme:me];

bdrv.enableFullScreenMode = YES;

bdrv.delegate = self;

bdvp = [[BDRecognizerViewParamsObject alloc]init];

bdvp.apiKey = @"pgk2mk3AZl2Uz5y6cydQTmDR";

bdvp.secretKey = @"62c14997cf54b83c94fad2f93d8bc88b";

//在按鈕點擊事件中

[bdrv startWithParams:bdvp];

//調用 BDRecognizerViewDelegate代理中的方法

//語音識別結果返回

-(void)onEndWithViews:(BDRecognizerViewController *)aBDRecognizerViewController withResults:(NSArray *)aResults{

//將獲取的文字添加到文本控件上

_label.text = [[[[aResults lastObject]lastObject]allKeys]lastObject];

}

//錄音數據返回

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

}

//錄音結束

- (void)onRecordEnded{

}