2018-12-21

#import "ViewController.h"

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "BDVRRawDataRecognizer.h"

#import "BDVRFileRecognizer.h"

@interfaceViewController ()

{

? ? BDRecognizerViewController *bdvc;

? ? NSMutableData *Mdata;


? ? BDRecognizerViewParamsObject *bdvp;

? ? UITextView *textV;


}

@end

@implementation ViewController

- (void)viewDidLoad {

? ? [superviewDidLoad];



? ? UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

? ? button.frame = CGRectMake(100,100,100,30);

? ? button.backgroundColor = [UIColor lightGrayColor];

? ? button.layer.cornerRadius =10;

? ? [button setTitle:@"點(diǎn)擊說話"forState:UIControlStateNormal];

? ? [button addTarget:selfaction:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:button];


? ? BDTheme *me = [BDTheme lightBlueTheme];

? ? //初始化

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


? ? //設(shè)置代理

? ? bdvc.delegate =self;

? ? //全屏

? ? bdvc.enableFullScreenMode =YES;


? ? bdvp = [[BDRecognizerViewParamsObject alloc] init];


? ? bdvp.apiKey =@"S0UrbTi31Yi6hTGjssCk0hzR";

? ? bdvp.secretKey =@"adb44d9f61aa57d86bcf970572c2f568";

? ? //初始化文本框

? ? textV = [[UITextView alloc] initWithFrame:CGRectMake(100,200,200,200)];

? ? textV.layer.borderWidth =1;

? ? [self.view addSubview:textV];


}

- (void)clickButton

{

? ? Mdata = [[NSMutableData alloc] init];


? ? [bdvc startWithParams:bdvp];

}

#pragma mark -- 代理方法

/**

?* @brief 語音識(shí)別結(jié)果返回,搜索和輸入模式結(jié)果返回的結(jié)構(gòu)不相同

?*

?* @param aBDRecognizerView 彈窗UI

?* @param aResults 返回結(jié)果,搜索結(jié)果為數(shù)組,輸入結(jié)果也為數(shù)組,但元素為字典

?*/

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

{

? ? textV.text = [[[[aResults objectAtIndex:0]objectAtIndex:0]allKeys]objectAtIndex:0];


}

/**

?* @brief 錄音數(shù)據(jù)返回

?*

?* @param recordData 錄音數(shù)據(jù)

?* @param sampleRate 采樣率

?*/

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

{

? ? //拼接

? ? [Mdata appendData:recordData];

}

@end




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

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

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