百度语音使用步骤(语音识别接入流程)

请参考《百度语音开放平台使用指南》创建应用,开通服务并完成个性化设置。


引入编译需要的Framework

BDVRClient包含的功能以及需要的Framework有:

功能                                                                  framework名称

录音和播放                                                  AudioToolbox.framework

                                                                    AVFoundation.framework

网络状态检测                                              SystemConfiguration.framework

判断当前网络连接类型(2G/3G/4G        CoreTelephony.framework

生成设备UDID                                             Security.framework

支持gzip压缩                                               libz.1.dylib

网络模块                                                     CFNetwork.framework

获取设备地理位置以提高识别准确度          CoreLocation.framework

支持识别控件                                              OpenGLES.framework

                                                                    QuartzCore.framework

                                                                    GLKit.framework

                                                                    CoreGraphics.framework

                                                                    CoreText.framework



ViewController.m代码



#import "ViewController.h"

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"

#import "BDVoiceRecognitionClient.h"

@interface ViewController ()<BDRecognizerViewDelegate>

{

    //创建语音界面对象

    BDRecognizerViewController * BDVC;

    //创建接受语音的界面

    BDRecognizerViewParamsObject * bdvc;

    NSMutableData * allData;

}

@property(nonatomic,strong)UITextView * vw;


@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    UIButton * btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.frame=CGRectMake(60, 300, 60, 50);

    [btn setTitle:@"开始识别" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(click1) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

    UIButton * btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn2.frame=CGRectMake(120, 300, 60, 50);

    [btn2 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];

    [btn2 setTitle:@"清除" forState:UIControlStateNormal];

    [self.view addSubview:btn2];

    self.vw=[[UITextView alloc]initWithFrame:CGRectMake(20, 20,self.view.frame.size.width-40, 200)];

    self.vw.backgroundColor=[UIColor grayColor];

    [self.view addSubview:self.vw];

    //设置主题

    BDTheme * theme=[BDTheme lightGreenTheme];

    BDVC=[[BDRecognizerViewController alloc]initWithOrigin:CGPointMake(9,128) withTheme:theme];

    BDVC.delegate=self;

    BDVC.enableFullScreenMode=YES;

    

    bdvc=[[BDRecognizerViewParamsObject alloc]init];

    

    bdvc.apiKey=@"***********************************";

    bdvc.secretKey=@"***********************************";

}

-(void)click1{

    [BDVC startWithParams:bdvc];

    allData =[[NSMutableData alloc]init];

}


-(void)click2{

    self.vw.text=nil;

}

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

    //可以不写内容但是必须有

}

- (void)onPartialResults:(NSString *)results{

    NSMutableString * ss=[[NSMutableString alloc]init];

    [ss appendString:results];

    self.vw.text=ss;

}

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


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