百度语音 ??

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

#import "BDVRRawDataRecognizer.h"

#import "BDVRFileRecognizer.h"

@interface ViewController ()

{

    BDRecognizerViewController *bdvc;

    NSMutableData *Mdata;


    BDRecognizerViewParamsObject *bdvp;

    UITextView*textV;


}

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];



    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

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

    button.backgroundColor= [UIColorlightGrayColor];

    button.layer.cornerRadius = 10;

    [buttonsetTitle:@"点击说话" forState:UIControlStateNormal];

    [buttonaddTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:button];


    BDTheme*me = [BDThemelightBlueTheme];

    //初始化

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


    //设置代理

    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= [[NSMutableDataalloc]init];


    [bdvc startWithParams:bdvp];

}

#pragma mark -- 代理方法

/**

 * @brief 语音识别结果返回,搜索和输入模式结果返回的结构不相同

 *

 * @paramaBDRecognizerView 弹窗UI

 * @param aResults 返回结果,搜索结果为数组,输入结果也为数组,但元素为字典

 */

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

{

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


}

/**

 * @brief 录音数据返回

 *

 * @param recordData 录音数据

 * @param sampleRate 采样率

 */

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

{

    //拼接

    [MdataappendData:recordData];

}

你可能感兴趣的:(百度语音 ??)