|
|
@@ -22,6 +22,7 @@
|
|
|
_channel = [FlutterMethodChannel
|
|
|
methodChannelWithName:@"speech_plugin"
|
|
|
binaryMessenger:[registrar messenger]];
|
|
|
+ [IFlySetting setLogFile:LVL_ALL];
|
|
|
SpeechPlugin* instance = [[SpeechPlugin alloc] init];
|
|
|
[registrar addMethodCallDelegate:instance channel: _channel];
|
|
|
}
|
|
|
@@ -166,7 +167,7 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
-- (void) configEvaluator {
|
|
|
+- (void)configEvaluator {
|
|
|
[self.iFlySpeechEvaluator setParameter:@"" forKey:[IFlySpeechConstant PARAMS]];
|
|
|
[self.iFlySpeechEvaluator setParameter:@"read_sentence" forKey:[IFlySpeechConstant ISE_CATEGORY]];
|
|
|
[self.iFlySpeechEvaluator setParameter:@"en_us" forKey:[IFlySpeechConstant LANGUAGE]];
|
|
|
@@ -201,16 +202,22 @@
|
|
|
[self.iFlySpeechEvaluator stopListening];
|
|
|
}];
|
|
|
} else {
|
|
|
- NSData *voiceData = [M4aToPcmHelper M4aToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path]];
|
|
|
- if(voiceData == nil) {
|
|
|
+ NSURL *voiceUrl = [M4aToPcmHelper M4aToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path]];
|
|
|
+ if(voiceUrl == nil) {
|
|
|
+ NSLog(@"voice url is nil");
|
|
|
[_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
return;
|
|
|
}
|
|
|
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
|
|
NSMutableData *buffer= [NSMutableData dataWithData:[text dataUsingEncoding:encoding]];
|
|
|
[self.iFlySpeechEvaluator startListening:buffer params:nil];
|
|
|
- [self.iFlySpeechEvaluator writeAudio:voiceData];
|
|
|
- [self.iFlySpeechEvaluator stopListening];
|
|
|
+ dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+ NSData *data = [[NSData alloc] initWithContentsOfURL:voiceUrl];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [self.iFlySpeechEvaluator writeAudio:data];
|
|
|
+ [self.iFlySpeechEvaluator stopListening];
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
}else if(sdkType.intValue == 1){
|
|
|
//调用池声解析
|
|
|
@@ -267,7 +274,7 @@
|
|
|
|
|
|
// 评测结果回调
|
|
|
- (void)onResults:(NSData *)results isLast:(BOOL)isLast {
|
|
|
-
|
|
|
+ NSLog(@"onResults");
|
|
|
BOOL isSuccess = false;
|
|
|
if (isLast) {
|
|
|
if(results) {
|
|
|
@@ -276,6 +283,7 @@
|
|
|
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
|
|
strResults = [[NSString alloc] initWithBytes:chResult length:[results length] encoding:encoding];
|
|
|
if(strResults != nil) {
|
|
|
+ NSLog(@"onResults is success");
|
|
|
ISEResultXmlParser *parser = [ISEResultXmlParser alloc];
|
|
|
[parser setDelegate:self];
|
|
|
[parser parserXml:strResults];
|
|
|
@@ -284,13 +292,16 @@
|
|
|
}
|
|
|
}
|
|
|
if(isSuccess == NO){
|
|
|
+ NSLog(@"onResults is not success");
|
|
|
self.xunFeiOneVoice = false;
|
|
|
[_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)onCompleted:(IFlySpeechError *)errorCode {
|
|
|
+ NSLog(@"onCompleted");
|
|
|
if (errorCode.errorCode != 0 || self.xunFeiOneVoice == true) {
|
|
|
+ NSLog(@"onCompleted not error code");
|
|
|
self.xunFeiOneVoice = false;
|
|
|
[_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
@@ -316,16 +327,20 @@
|
|
|
#pragma mark - ISEResultXmlParser delegate
|
|
|
|
|
|
-(void)onISEResultXmlParser:(NSXMLParser *)parser Error:(NSError*)error {
|
|
|
+ NSLog(@"onISEResultXmlParser");
|
|
|
if (error.code != 0) {
|
|
|
[_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-(void)onISEResultXmlParserResult:(ISEResult*)result {
|
|
|
+ NSLog(@"onISEResultXmlParserResult");
|
|
|
if (result.is_rejected) {
|
|
|
+ NSLog(@"onISEResultXmlParserResult reject");
|
|
|
self.xunFeiOneVoice = false;
|
|
|
[_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
} else {
|
|
|
+ NSLog(@"onISEResultXmlParserResult not reject");
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
[dic setValue:self.index forKey:@"index"];
|
|
|
[dic setValue:@(result.total_score) forKey:@"score"];
|