百度语音 离在线

官网文档 前期的配置 http://ai.baidu.com/docs#/ASR-iOS-SDK/top


#import "ViewController.h"

#import "BDSEventManager.h"

#import "BDSASRDefines.h"

#import "BDSASRParameters.h"

#import "BDTheme.h"

#import "BDRecognizerViewParamsObject.h"

#import "BDRecognizerViewController.h"

#import "BDRecognizerViewDelegate.h"







const NSString* API_KEY = @"BmezSBt9Z8BGw1yGZtiF4fLR";

const NSString* SECRET_KEY = @"GQ4WoULV8Afh1hIGVwTu8rE705u7Sy9B";

constNSString* APP_ID =@"15204639";





@interface ViewController ()


//这个是宝贝

@property (weak, nonatomic) IBOutlet UITextField *inputTF;

- (IBAction)voiceRecognize:(id)sender;

@property (strong, nonatomic) BDSEventManager *asrEventManager;

@property(nonatomic,strong)BDRecognizerViewController*recognizerViewController;

@end




@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];


    self.asrEventManager = [BDSEventManager createEventManagerWithName:BDS_ASR_NAME];

    //设置DEBUG_LOG的级别

    [self.asrEventManager setParameter:@(EVRDebugLogLevelTrace) forKey:BDS_ASR_DEBUG_LOG_LEVEL];

    //配置API_KEY 和 SECRET_KEY 和 APP_ID

    [self.asrEventManager setParameter:@[API_KEY, SECRET_KEY] forKey:BDS_ASR_API_SECRET_KEYS];

    [self.asrEventManager setParameter:APP_ID forKey:BDS_ASR_OFFLINE_APP_CODE];

    //配置端点检测(二选一)

    NSString *modelVAD_filepath = [[NSBundle mainBundle] pathForResource:@"bds_easr_basic_model" ofType:@"dat"];

    [self.asrEventManager setParameter:modelVAD_filepath forKey:BDS_ASR_MODEL_VAD_DAT_FILE];

    [self.asrEventManager setParameter:@(YES) forKey:BDS_ASR_ENABLE_MODEL_VAD];

    //      [self configDNNMFE];


    //    [self.asrEventManager setParameter:@"15361" forKey:BDS_ASR_PRODUCT_ID];

    // ---- 语义与标点 -----

    [self.asrEventManager setParameter:@(YES) forKey:BDS_ASR_ENABLE_NLU];

    [self.asrEventManager setParameter:@"1536" forKey:BDS_ASR_PRODUCT_ID];

    //    [self enablePunctuation];

    // ------------------------



}

- (IBAction)voiceRecognize:(id)sender {

    [self.asrEventManager setParameter:@"" forKey:BDS_ASR_AUDIO_FILE_PATH];

    BDRecognizerViewParamsObject *paramsObject = [[BDRecognizerViewParamsObject alloc] init];

    paramsObject.isShowTipAfterSilence = YES;

    paramsObject.isShowHelpButtonWhenSilence = NO;

    paramsObject.tipsTitle=@"您可以这样问";

    paramsObject.tipsList= [NSArrayarrayWithObjects:@"我要吃饭",@"我要买电影票",@"我要订酒店",nil];

    paramsObject.waitTime2ShowTip=0.5;

    paramsObject.isHidePleaseSpeakSection = YES;

    paramsObject.disableCarousel=YES;

    self.recognizerViewController = [[BDRecognizerViewController alloc] initRecognizerViewControllerWithOrigin:CGPointMake(9, 80)

                                                                                                         theme:nil

                                                                                              enableFullScreen:YES

                                                                                                  paramsObject:paramsObject

                                                                                                      delegate:self];


    [self.recognizerViewController startVoiceRecognition];

}





#pragma mark =======  BDRecognizerViewDelegate  =============

- (void)onEndWithViews:(BDRecognizerViewController*)aBDRecognizerViewController withResult:(id)aResult{

    NSLog(@"%@",aResult);

    NSString* res =[aResult[@"results_recognition"]firstObject];

    dispatch_async(dispatch_get_main_queue(), ^{

        self.inputTF.text=res;

    });

}

- (void)onError:(int)errClass errCode:(int)errCode errDescription:(NSString*)errDescription{


    NSLog(@"%@",errDescription);


}

@end

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