|
@@ -14,7 +14,7 @@
|
|
|
#import "NLSVoiceRecorder.h"
|
|
|
|
|
|
@interface PQSpeechTranscriberUtil ()<NeoNuiSdkDelegate,NlsVoiceRecorderDelegate> {
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
@property(nonatomic,strong) NeoNui* nui;
|
|
@@ -31,12 +31,12 @@
|
|
|
|
|
|
_voiceRecorder = [[NlsVoiceRecorder alloc] init];
|
|
|
_voiceRecorder.delegate = self;
|
|
|
-
|
|
|
+
|
|
|
[self initNui];
|
|
|
|
|
|
NSString *version = [NSString stringWithUTF8String:[_nui nui_get_version]];
|
|
|
NSLog(@"nui_get_version is %@",version);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return self;
|
|
|
|
|
@@ -46,7 +46,7 @@
|
|
|
|
|
|
/// 开始识别
|
|
|
- (void)startTranscriber{
|
|
|
-
|
|
|
+
|
|
|
if (_nui != nil) {
|
|
|
[_nui nui_dialog_start:MODE_P2T dialogParam:NULL];
|
|
|
} else {
|
|
@@ -61,7 +61,7 @@
|
|
|
[_nui nui_dialog_cancel:NO];
|
|
|
[_voiceRecorder stop:YES];
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
+
|
|
|
});
|
|
|
} else {
|
|
|
NSLog(@"in StopButHandler no nui alloc");
|
|
@@ -76,8 +76,8 @@
|
|
|
}
|
|
|
//请注意此处的参数配置,其中账号相关需要在Utils.m getTicket 方法中填入后才可访问服务
|
|
|
NSString * initParam = [self genInitParams];
|
|
|
-
|
|
|
- int initcode = [_nui nui_initialize:[initParam UTF8String] logLevel:LOG_LEVEL_VERBOSE saveLog:false];
|
|
|
+
|
|
|
+ int initcode = [_nui nui_initialize:[initParam UTF8String] logLevel:LOG_LEVEL_VERBOSE saveLog:false];
|
|
|
NSLog(@"初始化结果%d",initcode);
|
|
|
|
|
|
NSString * parameters = [self genParams];
|
|
@@ -119,9 +119,9 @@
|
|
|
NSString *bundlePath = [[NSBundle bundleWithPath:strResourcesBundle] resourcePath];
|
|
|
NSString *id_string = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
|
|
NSString *debug_path = [self createDir];
|
|
|
-//
|
|
|
+ //
|
|
|
NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
|
|
|
-
|
|
|
+
|
|
|
[dictM setObject:bundlePath forKey:@"workspace"];
|
|
|
[dictM setObject:debug_path forKey:@"debug_path"];
|
|
|
[dictM setObject:id_string forKey:@"device_id"];
|
|
@@ -130,9 +130,9 @@
|
|
|
//从阿里云获取appkey和token进行语音服务访问
|
|
|
[dictM setObject:@"oTOh8zDVK6iswF9o" forKey:@"app_key"];
|
|
|
[dictM setObject:@"f9fea6e2a72e4187b24facf30016e090" forKey:@"token"];
|
|
|
-
|
|
|
+
|
|
|
//由于token 24小时过期,可以参考getTicket实现从阿里云服务动态获取
|
|
|
-// [_utils getTicket:dictM];
|
|
|
+ // [_utils getTicket:dictM];
|
|
|
[dictM setObject:@"wss://nls-gateway.cn-shanghai.aliyuncs.com:443/ws/v1" forKey:@"url"];
|
|
|
|
|
|
NSData *data = [NSJSONSerialization dataWithJSONObject:dictM options:NSJSONWritingPrettyPrinted error:nil];
|
|
@@ -144,7 +144,7 @@
|
|
|
NSMutableDictionary *nls_config = [NSMutableDictionary dictionary];
|
|
|
//是否返回中间识别结果,默认值:False。
|
|
|
[nls_config setValue:@YES forKey:@"enable_intermediate_result"];
|
|
|
-
|
|
|
+
|
|
|
//是否在后处理中添加标点,默认值:False
|
|
|
[nls_config setValue:@YES forKey:@"enable_punctuation_prediction"];
|
|
|
//是否在后处理中执行ITN。设置为true时,中文数字将转为阿拉伯数字输出,默认值:False。
|
|
@@ -169,8 +169,8 @@
|
|
|
[dictM setValue:@(SERVICE_TYPE_SPEECH_TRANSCRIBER) forKey:@"service_type"];
|
|
|
|
|
|
|
|
|
-// 如果有HttpDns则可进行设置
|
|
|
-// [dictM setObject:[_utils getDirectIp] forKey:@"direct_ip"];
|
|
|
+ // 如果有HttpDns则可进行设置
|
|
|
+ // [dictM setObject:[_utils getDirectIp] forKey:@"direct_ip"];
|
|
|
|
|
|
NSData *data = [NSJSONSerialization dataWithJSONObject:dictM options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
NSString * jsonStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
|
|
@@ -208,7 +208,7 @@
|
|
|
retCode:(int)code {
|
|
|
NSLog(@"onNuiEventCallback event %d finish %d", nuiEvent, finish);
|
|
|
if (nuiEvent == EVENT_ASR_PARTIAL_RESULT || nuiEvent == EVENT_ASR_RESULT || nuiEvent == EVENT_SENTENCE_END) {
|
|
|
-
|
|
|
+
|
|
|
NSString *result = [NSString stringWithUTF8String:asr_result];
|
|
|
NSLog(@"识别结果: %@ finish %d", result, finish);
|
|
|
} else if (nuiEvent == EVENT_ASR_ERROR) {
|
|
@@ -221,7 +221,7 @@
|
|
|
//finish 为真(可能是发生错误,也可能是完成识别)表示一次任务生命周期结束,可以开始新的识别
|
|
|
if (finish) {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -254,7 +254,7 @@
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
return 0;
|