소스 검색

修复bug

rhyme 5 년 전
부모
커밋
7d49ec2a7b
1개의 변경된 파일35개의 추가작업 그리고 27개의 파일을 삭제
  1. 35 27
      ios/Classes/SpeechPlugin.m

+ 35 - 27
ios/Classes/SpeechPlugin.m

@@ -32,7 +32,7 @@
         [self iflyInit];
         self.oralEvaluation=[[TAIOralEvaluation alloc]init];
         self.oralEvaluation.delegate=self;
-        
+        result(nil);
     }  else if ([@"evaluatorByAudio" isEqualToString:call.method]) {
         NSNumber* index = call.arguments[@"index"];
         NSString* recordPath = call.arguments[@"recordPath"];
@@ -214,27 +214,22 @@
         //调用池声解析
         [self chivosInit:text];
         
-        if(isVideo){
-            
-        }else {
-            int   bytes = 0;
-            char  buf[1024]={0};
-            FILE *file = NULL;
-            const char * audiopath = [path UTF8String];
-            file = fopen(audiopath, "rb");//待评分音频地址
-            if(!file)
-            {
-                printf("read file error!\n");
-                return;
-            }
-            //            fseek(file, 44, SEEK_SET); //wav音频文件需要跳过头文件信息,其它音频格式不需要
-            while ((bytes = (int)fread(buf, 1, 1024, file)))
-            {
-                aiengine_feed(_engine, buf, bytes);
-            }
-            aiengine_stop(_engine);
-            
+        int   bytes = 0;
+        char  buf[1024]={0};
+        FILE *file = NULL;
+        const char * audiopath = [path UTF8String];
+        file = fopen(audiopath, "rb");//待评分音频地址
+        if(!file)
+        {
+            printf("read file error!\n");
+            return;
         }
+        //            fseek(file, 44, SEEK_SET); //wav音频文件需要跳过头文件信息,其它音频格式不需要
+        while ((bytes = (int)fread(buf, 1, 1024, file)))
+        {
+            aiengine_feed(_engine, buf, bytes);
+        }
+        aiengine_stop(_engine);
     }else {
         //调用腾讯解析
         TAIOralEvaluationParam *param =[[TAIOralEvaluationParam alloc]init];
@@ -362,12 +357,23 @@ int _aiengine_callback(const void *usrdata, const char *id, int type, const void
     NSArray<NSDictionary *>* worksList = dic[@"result"][@"details"];
     
     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
-    [dict setValue:self.index forKey:@"index"];
-    [dict setValue:@(score.doubleValue/20) forKey:@"score"];
-    [dict setValue:@(accuracy.doubleValue/20) forKey:@"accuracy_score"];
-    [dict setValue:@(fluency.doubleValue/20) forKey:@"fluency_score"];
-    [dict setValue:@(integrity.doubleValue/20) forKey:@"integrity_score"];
-    [dict setValue:worksList forKey:@"words"];
+    dict[@"index"] = self.index;
+    dict[@"score"] = @(score.doubleValue/20);
+    dict[@"accuracy_score"] = @(accuracy.doubleValue/20);
+    dict[@"fluency_score"] = @(fluency.doubleValue/20);
+    dict[@"integrity_score"] = @(integrity.doubleValue/20);
+    NSMutableArray<NSDictionary *> * works =[NSMutableArray array];
+    
+    for (NSDictionary* work in worksList) {
+        NSMutableDictionary *workDict = [NSMutableDictionary dictionary];
+        workDict[@"score"] = work[@"score"];
+        workDict[@"content"] = work[@"char"];
+        [works addObject:workDict];
+    }
+    NSData *data = [NSJSONSerialization dataWithJSONObject:works options:NSJSONWritingPrettyPrinted error:nil];
+    NSString *jsonStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
+    [dict setValue:jsonStr forKey:@"words"];
+    
     [_channel invokeMethod:@"evaluatorResult" arguments: dict];
     if (_engine) {
         aiengine_delete(_engine);
@@ -413,6 +419,8 @@ int _aiengine_callback(const void *usrdata, const char *id, int type, const void
         [dict setValue:@(pronAccuracy) forKey:@"accuracy_score"];
         [dict setValue:@(pronFluency) forKey:@"fluency_score"];
         [dict setValue:@(pronCompletion) forKey:@"integrity_score"];
+        NSData *data = [NSJSONSerialization dataWithJSONObject:workList options:NSJSONWritingPrettyPrinted error:nil];
+        NSString *jsonStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
         [dict setValue:workList forKey:@"words"];
         [_channel invokeMethod:@"evaluatorResult" arguments: dict];
     }else{