SpeechPlugin.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. #import "SpeechPlugin.h"
  2. #import <iflyMSC/iflyMSC.h>
  3. #import "M4aToPcmHelper.h"
  4. #import "Mp4ToPcmHelper.h"
  5. #import "Results/ISEResult.h"
  6. #import "Results/ISEResultXmlParser.h"
  7. #import "Results/ISEResultTools.h"
  8. #import "aiengine.h"
  9. #import <TAISDK/TAISDK.h>
  10. #import <TAISDK/TAIOralEvaluation.h>
  11. @interface SpeechPlugin () <IFlySpeechEvaluatorDelegate, ISEResultXmlParserDelegate,TAIOralEvaluationDelegate>
  12. @property (nonatomic, strong) IFlySpeechEvaluator *iFlySpeechEvaluator;
  13. @property (nonatomic, strong) NSNumber *index;
  14. @property struct aiengine * engine;
  15. @property (strong, nonatomic) TAIOralEvaluation *oralEvaluation;
  16. @property (nonatomic) BOOL xunFeiOneVoice;
  17. @end
  18. @implementation SpeechPlugin
  19. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  20. _channel = [FlutterMethodChannel
  21. methodChannelWithName:@"speech_plugin"
  22. binaryMessenger:[registrar messenger]];
  23. SpeechPlugin* instance = [[SpeechPlugin alloc] init];
  24. [registrar addMethodCallDelegate:instance channel: _channel];
  25. }
  26. - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  27. if ([@"getPlatformVersion" isEqualToString:call.method]) {
  28. result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  29. } else if ([@"initSpeechSdk" isEqualToString:call.method]) {
  30. [self iflyInit];
  31. self.oralEvaluation=[[TAIOralEvaluation alloc]init];
  32. self.oralEvaluation.delegate=self;
  33. result(nil);
  34. } else if ([@"evaluatorByAudio" isEqualToString:call.method]) {
  35. NSNumber* index = call.arguments[@"index"];
  36. NSString* recordPath = call.arguments[@"recordPath"];
  37. NSString* text = call.arguments[@"en"];
  38. NSString* pathEvaluatorDecode = call.arguments[@"pathEvaluatorDecode"];
  39. NSString* videoId = call.arguments[@"videoId"];
  40. NSNumber* evaluatorType = call.arguments[@"evaluatorType"];
  41. NSNumber* sdkType = call.arguments[@"sdkType"];
  42. [self evaluateVoice:index andPath:recordPath andText:text andIsVideo:false pathEvaluatorDecode:pathEvaluatorDecode videoId:videoId evaluatorType:evaluatorType sdkType:sdkType];
  43. } else if ([@"evaluatorByMp4" isEqualToString:call.method]) {
  44. NSNumber* index = call.arguments[@"index"];
  45. NSString* recordPath = call.arguments[@"recordPath"];
  46. NSString* text = call.arguments[@"en"];
  47. NSString* pathEvaluatorDecode = call.arguments[@"pathEvaluatorDecode"];
  48. NSString* videoId = call.arguments[@"videoId"];
  49. NSNumber* evaluatorType = call.arguments[@"evaluatorType"];
  50. NSNumber* sdkType = call.arguments[@"sdkType"];
  51. [self evaluateVoice:index andPath:recordPath andText:text andIsVideo:true
  52. pathEvaluatorDecode:pathEvaluatorDecode videoId:videoId evaluatorType:evaluatorType sdkType:sdkType];
  53. } else {
  54. result(FlutterMethodNotImplemented);
  55. }
  56. }
  57. #pragma mark - Bridge Actions
  58. - (void)iflyInit {
  59. [IFlySpeechUtility createUtility:@"appid=5db7af6b"];
  60. self.iFlySpeechEvaluator = [IFlySpeechEvaluator sharedInstance];
  61. self.iFlySpeechEvaluator.delegate = self;
  62. [self configEvaluator];
  63. }
  64. - (void)chivosInit:(NSString *)en
  65. {
  66. char cfg[4096];
  67. char version[512] = {0};
  68. char record_id[64] = {0};
  69. char param[4096];
  70. NSString* user_id = @"ios_user";
  71. /*获取当前SDK版本号*/
  72. aiengine_opt(NULL, AIENGINE_OPT_GET_VERSION, version, sizeof(version));
  73. NSLog(@"version: %s\n",version);
  74. /*获取证书路径*/
  75. NSString * provision = [[NSBundle mainBundle] pathForResource:@"aiengine" ofType:@"provision"];
  76. /*引擎初始化传参设置*/
  77. NSMutableDictionary *jsonDic = [[NSMutableDictionary alloc] initWithCapacity:10];
  78. /*授权参数*/
  79. [jsonDic setValue:@"157775873600002d" forKey:@"appKey"];
  80. [jsonDic setValue:@"a6c766845f9a83974aed16f103e60621" forKey:@"secretKey"];
  81. [jsonDic setValue:provision forKey:@"provision"];
  82. /*日志传参*/
  83. NSMutableDictionary *logDic = [[NSMutableDictionary alloc] init];
  84. NSString *logFileName = @"log.txt";
  85. [logDic setValue:[NSNumber numberWithInt:0] forKey:@"enable"];
  86. [logDic setValue:logFileName forKey:@"output"];
  87. /*服务链接参数*/
  88. NSMutableDictionary *cloudDic = [[NSMutableDictionary alloc] init];
  89. NSString *serverPath = @"wss://cloud.chivox.com:443";
  90. [cloudDic setValue:[NSNumber numberWithInt:1] forKey:@"enable"];
  91. [cloudDic setValue:serverPath forKey:@"server"];
  92. [cloudDic setValue:[NSNumber numberWithInt:60] forKey:@"serverTimeout"];
  93. /*初始化传参设置*/
  94. [jsonDic setValue:logDic forKey:@"prof"];
  95. [jsonDic setValue:cloudDic forKey:@"cloud"];
  96. NSString *jsonString;
  97. jsonString = [self dicToString:jsonDic];
  98. /*cfg赋值:string转char*/
  99. strcpy(cfg, [jsonString UTF8String]);
  100. NSLog(@"cfg: %s\n",cfg);
  101. /*评分引擎初始化*/
  102. _engine = aiengine_new(cfg);
  103. NSLog(@"engine: %p\n", _engine);
  104. /*引擎启用param传参设置*/
  105. NSMutableDictionary *paramDic = [[NSMutableDictionary alloc] initWithCapacity:10];
  106. /*在线离线参数配置(cloud/native)*/
  107. [paramDic setValue:@"cloud" forKey:@"coreProvideType"];
  108. /*音量实时返回参数设置(0关/1开)*/
  109. [paramDic setValue:[NSNumber numberWithInt:0] forKey:@"soundIntensityEnable"];
  110. /*appUser传参*/
  111. NSMutableDictionary *appDic = [[NSMutableDictionary alloc] init];
  112. [appDic setValue:user_id forKey:@"userId"];
  113. /*audio音频数据传参*/
  114. NSMutableDictionary *audioDic = [[NSMutableDictionary alloc] init];
  115. [audioDic setValue:@"m4a" forKey:@"audioType"];//音频编码格式
  116. [audioDic setValue:[NSNumber numberWithInt:16000] forKey:@"sampleRate"];//音频采样率
  117. [audioDic setValue:[NSNumber numberWithInt:1] forKey:@"channel"];//单声道设置
  118. [audioDic setValue:[NSNumber numberWithInt:2] forKey:@"sampleBytes"];//采样字节数(1-单字节-8位,2-双字节-16位)
  119. /*内核request传参*/
  120. NSMutableDictionary *requestDic = [[NSMutableDictionary alloc] init];
  121. //内核类型设置cn.word.raw/cn.sent.raw/cn.pred.raw
  122. [requestDic setValue:@"en.sent.score" forKey:@"coreType"];
  123. [requestDic setValue:en forKey:@"refText"];//评测文本
  124. [requestDic setValue:[NSNumber numberWithInt:100] forKey:@"rank"];//总分分制
  125. [requestDic setValue:[NSNumber numberWithInt:1] forKey:@"attachAudioUrl"];
  126. [requestDic setValue:[NSNumber numberWithInt:1] forKey:@"precision"];//段落评分精度设置(0.5/1)
  127. [paramDic setValue:appDic forKey:@"app"];
  128. [paramDic setValue:audioDic forKey:@"audio"];
  129. [paramDic setValue:requestDic forKey:@"request"];
  130. NSString *paramString;
  131. paramString = [self dicToString:paramDic];
  132. /*cfg赋值:string转char*/
  133. strcpy(param, [paramString UTF8String]);
  134. int rv = 0;
  135. rv = aiengine_start(_engine,param,record_id,(aiengine_callback)_aiengine_callback, (__bridge const void *)(self));
  136. if (rv) {
  137. NSLog(@"aiengine_start() failed: %d\n", rv);
  138. return;
  139. }
  140. }
  141. /*字典转为String*/
  142. - (NSString *)dicToString: (NSMutableDictionary *) jsonDictionary{
  143. NSError *error;
  144. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:0 error:&error];
  145. NSString *jsString;
  146. if (!jsonData) {
  147. NSLog(@"sorry you get an error:%@",error);
  148. } else {
  149. jsString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  150. }
  151. NSLog(@"引擎初始化传参#####:%@",jsString);
  152. return jsString;
  153. }
  154. - (void) configEvaluator {
  155. [self.iFlySpeechEvaluator setParameter:@"" forKey:[IFlySpeechConstant PARAMS]];
  156. [self.iFlySpeechEvaluator setParameter:@"read_sentence" forKey:[IFlySpeechConstant ISE_CATEGORY]];
  157. [self.iFlySpeechEvaluator setParameter:@"en_us" forKey:[IFlySpeechConstant LANGUAGE]];
  158. [self.iFlySpeechEvaluator setParameter:@"5000" forKey:[IFlySpeechConstant VAD_BOS]];
  159. [self.iFlySpeechEvaluator setParameter:@"1800" forKey:[IFlySpeechConstant VAD_EOS]];
  160. [self.iFlySpeechEvaluator setParameter:@"-1" forKey:[IFlySpeechConstant SPEECH_TIMEOUT]];
  161. [self.iFlySpeechEvaluator setParameter:@"complete" forKey:[IFlySpeechConstant ISE_RESULT_LEVEL]];
  162. [self.iFlySpeechEvaluator setParameter:@"16000" forKey:[IFlySpeechConstant SAMPLE_RATE]];
  163. [self.iFlySpeechEvaluator setParameter:@"xml" forKey:[IFlySpeechConstant ISE_RESULT_TYPE]];
  164. [self.iFlySpeechEvaluator setParameter:@"0" forKey:@"plev"];
  165. [self.iFlySpeechEvaluator setParameter:@"-1" forKey:@"audio_source"];
  166. }
  167. - (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
  168. {
  169. self.index = index;
  170. if (sdkType.intValue == 0) {
  171. //调用讯飞解析
  172. self.xunFeiOneVoice = true;
  173. [self.iFlySpeechEvaluator setParameter:evaluatorType.stringValue forKey:@"plev"];
  174. if(isVideo) {
  175. [Mp4ToPcmHelper Mp4ToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path] completion:^(NSData *data) {
  176. if(data == nil) {
  177. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  178. return;
  179. }
  180. NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
  181. NSMutableData *buffer= [NSMutableData dataWithData:[text dataUsingEncoding:encoding]];
  182. [self.iFlySpeechEvaluator startListening:buffer params:nil];
  183. [self.iFlySpeechEvaluator writeAudio:data];
  184. [self.iFlySpeechEvaluator stopListening];
  185. }];
  186. } else {
  187. NSData *voiceData = [M4aToPcmHelper M4aToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path]];
  188. if(voiceData == nil) {
  189. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  190. return;
  191. }
  192. NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
  193. NSMutableData *buffer= [NSMutableData dataWithData:[text dataUsingEncoding:encoding]];
  194. [self.iFlySpeechEvaluator startListening:buffer params:nil];
  195. [self.iFlySpeechEvaluator writeAudio:voiceData];
  196. [self.iFlySpeechEvaluator stopListening];
  197. }
  198. }else if(sdkType.intValue == 1){
  199. //调用池声解析
  200. [self chivosInit:text];
  201. int bytes = 0;
  202. char buf[1024]={0};
  203. FILE *file = NULL;
  204. const char * audiopath = [path UTF8String];
  205. file = fopen(audiopath, "rb");//待评分音频地址
  206. if(!file)
  207. {
  208. printf("read file error!\n");
  209. return;
  210. }
  211. // fseek(file, 44, SEEK_SET); //wav音频文件需要跳过头文件信息,其它音频格式不需要
  212. while ((bytes = (int)fread(buf, 1, 1024, file)))
  213. {
  214. aiengine_feed(_engine, buf, bytes);
  215. }
  216. aiengine_stop(_engine);
  217. }else {
  218. //调用腾讯解析
  219. TAIOralEvaluationParam *param =[[TAIOralEvaluationParam alloc]init];
  220. param.sessionId = [[NSUUID UUID]UUIDString];
  221. param.appId =@"1301049120";
  222. param.workMode = TAIOralEvaluationWorkMode_Once;
  223. param.evalMode = TAIOralEvaluationEvalMode_Sentence;
  224. param.storageMode = TAIOralEvaluationStorageMode_Disable;
  225. param.serverType = TAIOralEvaluationServerType_English;
  226. param.scoreCoeff = 1.0;
  227. param.fileType = TAIOralEvaluationFileType_Wav;
  228. param.refText = text;
  229. param.secretId = @"AKIDUf0EEzc8NMpPmu4Po1zhXBZicKp5G7xZ";
  230. param.secretKey = @"WnsjKaqtgDVbV9cMtABwVptarwpWyBAt";
  231. TAIOralEvaluationData *data = [[TAIOralEvaluationData alloc] init];
  232. data.seqId = 1;
  233. data.bEnd = YES;
  234. data.audio = [NSData dataWithContentsOfFile:path];
  235. [self.oralEvaluation oralEvaluation:param data:data callback:^(TAIError *error) {
  236. //接口调用结果返回
  237. if(error){
  238. NSLog(@"调用腾讯失败:code:%ld , msg:%@",(long)error.code ,error.desc);
  239. }else{
  240. NSLog(@"调用腾讯成功");
  241. }
  242. }];
  243. }
  244. }
  245. #pragma mark - iFly delegate
  246. // 评测结果回调
  247. - (void)onResults:(NSData *)results isLast:(BOOL)isLast {
  248. BOOL isSuccess = false;
  249. if (isLast) {
  250. if(results) {
  251. const char* chResult = [results bytes];
  252. NSString* strResults = nil;
  253. NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
  254. strResults = [[NSString alloc] initWithBytes:chResult length:[results length] encoding:encoding];
  255. if(strResults != nil) {
  256. ISEResultXmlParser *parser = [ISEResultXmlParser alloc];
  257. [parser setDelegate:self];
  258. [parser parserXml:strResults];
  259. isSuccess = YES;
  260. }
  261. }
  262. }
  263. if(isSuccess == NO){
  264. self.xunFeiOneVoice = false;
  265. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  266. }
  267. }
  268. - (void)onCompleted:(IFlySpeechError *)errorCode {
  269. if (errorCode.errorCode != 0 || self.xunFeiOneVoice == true) {
  270. self.xunFeiOneVoice = false;
  271. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  272. }
  273. }
  274. - (void)onCancel {
  275. NSLog(@"取消录音");
  276. }
  277. - (void)onBeginOfSpeech {
  278. NSLog(@"开始录音");
  279. }
  280. - (void)onEndOfSpeech {
  281. NSLog(@"停止录音");
  282. }
  283. - (void)onVolumeChanged:(int)volume buffer:(NSData *)buffer {
  284. NSLog(@"音量改变");
  285. }
  286. #pragma mark - ISEResultXmlParser delegate
  287. -(void)onISEResultXmlParser:(NSXMLParser *)parser Error:(NSError*)error {
  288. if (error.code != 0) {
  289. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  290. }
  291. }
  292. -(void)onISEResultXmlParserResult:(ISEResult*)result {
  293. if (result.is_rejected) {
  294. self.xunFeiOneVoice = false;
  295. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  296. } else {
  297. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  298. [dic setValue:self.index forKey:@"index"];
  299. [dic setValue:@(result.total_score) forKey:@"score"];
  300. [dic setValue:@(result.accuracy_score) forKey:@"accuracy_score"];
  301. [dic setValue:@(result.fluency_score) forKey:@"fluency_score"];
  302. [dic setValue:@(result.integrity_score) forKey:@"integrity_score"];
  303. NSString* words = [ISEResultTools formatDetailsForLanguageEN: result.sentences];
  304. [dic setValue:words forKey:@"words"];
  305. self.xunFeiOneVoice = false;
  306. [_channel invokeMethod:@"evaluatorResult" arguments: dic];
  307. }
  308. }
  309. #pragma mark - chisheng回掉
  310. /*评分引擎回调方法*/
  311. int _aiengine_callback(const void *usrdata, const char *id, int type, const void *message, int size)
  312. {
  313. if (type == AIENGINE_MESSAGE_TYPE_JSON) {
  314. [(__bridge SpeechPlugin *)usrdata performSelectorOnMainThread:@selector(onChiResult:) withObject:[[NSString alloc] initWithUTF8String:(char *)message] waitUntilDone:NO];
  315. }
  316. return 0;
  317. }
  318. //返回的内容
  319. -(void) onChiResult:(NSString *) result{
  320. if(result == nil){
  321. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  322. return;
  323. }
  324. NSLog(@"返回的结果:%@",result);
  325. NSData *jsonData = [result dataUsingEncoding:NSUTF8StringEncoding];
  326. NSError *err = nil;
  327. NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  328. if(err) {
  329. NSLog(@"json解析失败:%@",err);
  330. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  331. return ;
  332. }
  333. NSNumber *score = dic[@"result"][@"overall"];
  334. NSNumber *integrity = dic[@"result"][@"integrity"];
  335. NSNumber *accuracy = dic[@"result"][@"accuracy"];
  336. NSNumber *fluency = dic[@"result"][@"fluency"][@"overall"];
  337. NSArray<NSDictionary *>* worksList = dic[@"result"][@"details"];
  338. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  339. dict[@"index"] = self.index;
  340. dict[@"score"] = @(score.doubleValue/20);
  341. dict[@"accuracy_score"] = @(accuracy.doubleValue/20);
  342. dict[@"fluency_score"] = @(fluency.doubleValue/20);
  343. dict[@"integrity_score"] = @(integrity.doubleValue/20);
  344. NSMutableArray<NSDictionary *> * works =[NSMutableArray array];
  345. for (NSDictionary* work in worksList) {
  346. NSMutableDictionary *workDict = [NSMutableDictionary dictionary];
  347. workDict[@"score"] = work[@"score"];
  348. workDict[@"content"] = work[@"char"];
  349. [works addObject:workDict];
  350. }
  351. NSData *data = [NSJSONSerialization dataWithJSONObject:works options:NSJSONWritingPrettyPrinted error:nil];
  352. NSString *jsonStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
  353. [dict setValue:jsonStr forKey:@"words"];
  354. [_channel invokeMethod:@"evaluatorResult" arguments: dict];
  355. if (_engine) {
  356. aiengine_delete(_engine);
  357. _engine = NULL;
  358. }
  359. }
  360. #pragma mark - 腾讯会掉
  361. - (void)oralEvaluation:(TAIOralEvaluation *)oralEvaluation onEvaluateData:(TAIOralEvaluationData *)data result:(TAIOralEvaluationRet *)result error:(TAIError *)error {
  362. //数据和结果回调(只有data.bEnd为YES,result有效)
  363. if (data.bEnd) {
  364. float pronFluency = result.pronFluency *5;
  365. float pronAccuracy = result.pronAccuracy;
  366. if(pronAccuracy == -1){
  367. pronAccuracy = 0;
  368. }else {
  369. pronAccuracy = pronAccuracy/20;
  370. }
  371. float pronCompletion = result.pronCompletion * 5;
  372. float totalScore = (pronFluency + pronAccuracy + pronCompletion)/ 3;
  373. NSMutableArray* workList =[NSMutableArray array];
  374. for (TAIOralEvaluationWord* work in result.words) {
  375. NSMutableDictionary *dic =[NSMutableDictionary dictionary];
  376. float score = work.pronAccuracy;
  377. if(score == -1.0){
  378. score = 0;
  379. }else{
  380. score = score/20;
  381. }
  382. dic[@"score"]= [NSNumber numberWithFloat:score];
  383. dic[@"content"] = work.word;
  384. [workList addObject:dic];
  385. }
  386. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  387. [dict setValue:self.index forKey:@"index"];
  388. [dict setValue:@(totalScore) forKey:@"score"];
  389. [dict setValue:@(pronAccuracy) forKey:@"accuracy_score"];
  390. [dict setValue:@(pronFluency) forKey:@"fluency_score"];
  391. [dict setValue:@(pronCompletion) forKey:@"integrity_score"];
  392. NSData *data = [NSJSONSerialization dataWithJSONObject:workList options:NSJSONWritingPrettyPrinted error:nil];
  393. NSString *jsonStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
  394. [dict setValue:workList forKey:@"words"];
  395. [_channel invokeMethod:@"evaluatorResult" arguments: dict];
  396. }else{
  397. [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
  398. }
  399. }
  400. @end