背景:
总监看我太无聊了,讯飞语音识别搞完了,就让我去搞一下百度语音识别。然后比较两种语音识别的准确率,哪种更高点。
个人认为吧,都差不多。百度稍微会好那么一点点。
不过,值得一提的是:虽然讯飞和百度的语音识别都是免费的,但是百度每天免费试用次数是20000次,而讯飞的每天只有500次。其他语音产品,也都是百度的免费次数多。讯飞和百度都有个性化词库,所谓个性化词库就是你说的语句,如果话中的词语包含在个性化词库中,那么会优先识别个性化词库的词。但是,百度除了有个性化词库之外,还有个语义解析,就是你设置好问答,然后你问上一句,他会自动答出下一句。好不好玩?讯飞不知道有没有,我没看到。
百度语音识别:
当然是要去百度语音开放平台注册应用啦,如果还没注册的,包括如何引入库,可以参考:iOS-百度语音合成的使用
//
// ViewController.m
// BirdBtn
//
// Created by HZhenF on 2017/9/25.
// Copyright © 2017年 GZHYTechnology. All rights reserved.
//
#import "ViewController.h"
#import "BDSEventManager.h"
#import "BDSASRDefines.h"
#import "BDSASRParameters.h"
#define ScreenW [UIScreen mainScreen].bounds.size.width
#define ScreenH [UIScreen mainScreen].bounds.size.height
const NSString* API_KEY = @"BCZkKhjhlFi10eGshX7NNEfY";
const NSString* SECRET_KEY = @"07b9795bbe95fa71a710c2179d80fc0b";
const NSString* APP_ID = @"10177498";
@interface ViewController ()<BDSClientASRDelegate>
@property(nonatomic,strong) BDSEventManager *asrManager;
@property(nonatomic,assign) BOOL isStartRecord;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CGFloat btn3W = 127;
CGFloat btn3H = 93;
CGFloat btn3X = 10;
CGFloat btn3Y = CGRectGetMaxY(btn2.frame) + 10;
UIButton *btn3 = [[UIButton alloc] initWithFrame:CGRectMake(btn3X, btn3Y, btn3W, btn3H)];
[btn3 setImage:[UIImage imageNamed:@"icon_logo_L"] forState:UIControlStateNormal];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
[btn3 addGestureRecognizer:longPress];
[self.view addSubview:btn3];
//配置百度语音识别
[self configureBDVoice];
}
-(void)configureBDVoice
{
//创建相关接口对象
self.asrManager = [BDSEventManager createEventManagerWithName:BDS_ASR_NAME];
//设置代理
[self.asrManager setDelegate:self];
//配置参数
//1.设置DEBUG_LOG的级别
[self.asrManager setParameter:@(EVRDebugLogLevelTrace) forKey:BDS_ASR_DEBUG_LOG_LEVEL];
//2.配置API_KEY 和 SECRET_KEY 和 APP_ID
[self.asrManager setParameter:@[API_KEY, SECRET_KEY] forKey:BDS_ASR_API_SECRET_KEYS];
[self.asrManager setParameter:APP_ID forKey:BDS_ASR_OFFLINE_APP_CODE];
//3.配置端点检测
NSString *modelVAD_filepath = [[NSBundle mainBundle] pathForResource:@"bds_easr_basic_model" ofType:@"dat"];
NSLog(@"modelVAD_filepath = %@",modelVAD_filepath);
[self.asrManager setParameter:modelVAD_filepath forKey:BDS_ASR_MODEL_VAD_DAT_FILE];
[self.asrManager setParameter:@(YES) forKey:BDS_ASR_ENABLE_MODEL_VAD];
//4.开启语义理解
[self.asrManager setParameter:@(YES) forKey:BDS_ASR_ENABLE_NLU];
[self.asrManager setParameter:@"15361" forKey:BDS_ASR_PRODUCT_ID];
//长按设置
[self.asrManager setParameter:@(YES) forKey:BDS_ASR_VAD_ENABLE_LONG_PRESS];
[self.asrManager setParameter:@(NO) forKey:BDS_ASR_ENABLE_LONG_SPEECH];
[self.asrManager setParameter:@(NO) forKey:BDS_ASR_NEED_CACHE_AUDIO];
[self.asrManager setParameter:@"" forKey:BDS_ASR_OFFLINE_ENGINE_TRIGGERED_WAKEUP_WORD];
[self.asrManager setParameter:nil forKey:BDS_ASR_AUDIO_FILE_PATH];
[self.asrManager setParameter:nil forKey:BDS_ASR_AUDIO_INPUT_STREAM];
self.isStartRecord = YES;
}
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
// NSLog(@"longPressAction");
if (self.isStartRecord) {
//发送指令:启动识别
[self.asrManager sendCommand:BDS_ASR_CMD_START];
self.isStartRecord = NO;
}
if (longPress.state == UIGestureRecognizerStateEnded) {
self.isStartRecord = YES;
//结束发送指令
[self.asrManager sendCommand:BDS_ASR_CMD_STOP];
}
}
-(void)VoiceRecognitionClientWorkStatus:(int)workStatus obj:(id)aObj
{
switch (workStatus) {
case EVoiceRecognitionClientWorkStatusNewRecordData: {
NSLog(@"EVoiceRecognitionClientWorkStatusNewRecordData");
break;
}
case EVoiceRecognitionClientWorkStatusStartWorkIng: {
NSLog(@"EVoiceRecognitionClientWorkStatusStartWorkIng");
break;
}
case EVoiceRecognitionClientWorkStatusStart: {
NSLog(@"EVoiceRecognitionClientWorkStatusStart");
break;
}
case EVoiceRecognitionClientWorkStatusEnd: {
NSLog(@"EVoiceRecognitionClientWorkStatusEnd");
break;
}
case EVoiceRecognitionClientWorkStatusFlushData: {
NSLog(@"EVoiceRecognitionClientWorkStatusFlushData");
break;
}
case EVoiceRecognitionClientWorkStatusFinish: {
NSLog(@"EVoiceRecognitionClientWorkStatusFinish");
NSLog(@"aObj = %@",aObj);
NSArray *contentArr = aObj[@"results_recognition"];
NSString *contentStr = contentArr[0];
NSLog(@"contentStr = %@",contentStr);
break;
}
case EVoiceRecognitionClientWorkStatusMeterLevel: {
NSLog(@"EVoiceRecognitionClientWorkStatusMeterLevel");
break;
}
case EVoiceRecognitionClientWorkStatusCancel: {
NSLog(@"EVoiceRecognitionClientWorkStatusCancel");
break;
}
case EVoiceRecognitionClientWorkStatusError: {
NSLog(@"EVoiceRecognitionClientWorkStatusError");
break;
}
case EVoiceRecognitionClientWorkStatusLoaded: {
NSLog(@"EVoiceRecognitionClientWorkStatusLoaded");
break;
}
case EVoiceRecognitionClientWorkStatusUnLoaded: {
NSLog(@"EVoiceRecognitionClientWorkStatusUnLoaded");
break;
}
case EVoiceRecognitionClientWorkStatusChunkThirdData: {
NSLog(@"EVoiceRecognitionClientWorkStatusChunkThirdData");
break;
}
case EVoiceRecognitionClientWorkStatusChunkNlu: {
NSLog(@"EVoiceRecognitionClientWorkStatusChunkNlu");
break;
}
case EVoiceRecognitionClientWorkStatusChunkEnd: {
NSLog(@"EVoiceRecognitionClientWorkStatusChunkEnd");
break;
}
case EVoiceRecognitionClientWorkStatusFeedback: {
NSLog(@"EVoiceRecognitionClientWorkStatusFeedback");
break;
}
case EVoiceRecognitionClientWorkStatusRecorderEnd: {
NSLog(@"EVoiceRecognitionClientWorkStatusRecorderEnd");
break;
}
case EVoiceRecognitionClientWorkStatusLongSpeechEnd: {
NSLog(@"EVoiceRecognitionClientWorkStatusLongSpeechEnd");
break;
}
default:
break;
}
}
@end
个性化词库和语义解析
里面有官方的格式,按照官方格式来弄就行。
弄完上传就好,个性化词库要等一个小时才能生效(讯飞、百度都是一个小时)。语义解析要等两个小时才能生效。