ソースを参照

修复录音评分不返回的问题

i2edu 5 年 前
コミット
6b0415bafe
1 ファイル変更21 行追加6 行削除
  1. 21 6
      ios/Classes/SpeechPlugin.m

+ 21 - 6
ios/Classes/SpeechPlugin.m

@@ -14,6 +14,7 @@
 @property (nonatomic, strong) NSNumber *index;
 @property struct aiengine * engine;
 @property (strong, nonatomic) TAIOralEvaluation *oralEvaluation;
+@property (nonatomic) BOOL xunFeiOneVoice;
 @end
 
 @implementation SpeechPlugin
@@ -181,10 +182,11 @@
 
 - (void) evaluateVoice: (NSNumber*)index andPath:(NSString*)path andText:(NSString*)text andIsVideo:(BOOL) isVideo pathEvaluatorDecode:(NSString*)pathEvaluatorDecode videoId:(NSString*)videoId evaluatorType:(NSNumber*)evaluatorType sdkType:(NSNumber*)sdkType
 {
-    
+
     self.index = index;
     if (sdkType.intValue == 0) {
         //调用讯飞解析
+        self.xunFeiOneVoice = true;
         [self.iFlySpeechEvaluator setParameter:evaluatorType.stringValue forKey:@"plev"];
         if(isVideo) {
             [Mp4ToPcmHelper Mp4ToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path] completion:^(NSData *data) {
@@ -265,6 +267,7 @@
 
 // 评测结果回调
 - (void)onResults:(NSData *)results isLast:(BOOL)isLast {
+
     BOOL isSuccess = false;
     if (isLast) {
         if(results) {
@@ -281,23 +284,33 @@
         }
     }
     if(isSuccess == NO){
+        self.xunFeiOneVoice = false;
          [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
     }
 }
 
 - (void)onCompleted:(IFlySpeechError *)errorCode {
-    if (errorCode.errorCode != 0) {
+    if (errorCode.errorCode != 0 || self.xunFeiOneVoice == true) {
+        self.xunFeiOneVoice = false;
         [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
     }
 }
 
-- (void)onCancel {}
+- (void)onCancel {
+    NSLog(@"取消录音");
+}
 
-- (void)onBeginOfSpeech {}
+- (void)onBeginOfSpeech {
+    NSLog(@"开始录音");
+}
 
-- (void)onEndOfSpeech {}
+- (void)onEndOfSpeech {
+    NSLog(@"停止录音");
+}
 
-- (void)onVolumeChanged:(int)volume buffer:(NSData *)buffer {}
+- (void)onVolumeChanged:(int)volume buffer:(NSData *)buffer {
+    NSLog(@"音量改变");
+}
 
 
 #pragma mark - ISEResultXmlParser delegate
@@ -310,6 +323,7 @@
 
 -(void)onISEResultXmlParserResult:(ISEResult*)result {
     if (result.is_rejected) {
+        self.xunFeiOneVoice = false;
         [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
     } else {
         NSMutableDictionary *dic = [NSMutableDictionary dictionary];
@@ -320,6 +334,7 @@
         [dic setValue:@(result.integrity_score) forKey:@"integrity_score"];
         NSString* words = [ISEResultTools formatDetailsForLanguageEN: result.sentences];
         [dic setValue:words forKey:@"words"];
+        self.xunFeiOneVoice = false;
         [_channel invokeMethod:@"evaluatorResult" arguments: dic];
     }
 }