|
|
@@ -7,22 +7,20 @@
|
|
|
#import "Results/ISEResultTools.h"
|
|
|
|
|
|
@interface SpeechPlugin () <IFlySpeechEvaluatorDelegate, ISEResultXmlParserDelegate>
|
|
|
-@property (nonatomic, strong) FlutterResult result;
|
|
|
@property (nonatomic, strong) IFlySpeechEvaluator *iFlySpeechEvaluator;
|
|
|
@property (nonatomic, strong) NSNumber *index;
|
|
|
@end
|
|
|
|
|
|
@implementation SpeechPlugin
|
|
|
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
|
|
- FlutterMethodChannel* channel = [FlutterMethodChannel
|
|
|
+ _channel = [FlutterMethodChannel
|
|
|
methodChannelWithName:@"speech_plugin"
|
|
|
binaryMessenger:[registrar messenger]];
|
|
|
SpeechPlugin* instance = [[SpeechPlugin alloc] init];
|
|
|
- [registrar addMethodCallDelegate:instance channel:channel];
|
|
|
+ [registrar addMethodCallDelegate:instance channel: _channel];
|
|
|
}
|
|
|
|
|
|
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
|
|
|
- self.result = result;
|
|
|
if ([@"getPlatformVersion" isEqualToString:call.method]) {
|
|
|
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
|
|
|
} else if ([@"initSpeechSdk" isEqualToString:call.method]) {
|
|
|
@@ -70,7 +68,7 @@
|
|
|
if(isVideo) {
|
|
|
[Mp4ToPcmHelper Mp4ToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path] completion:^(NSData *data) {
|
|
|
if(data == nil) {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
return;
|
|
|
}
|
|
|
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
|
|
@@ -82,7 +80,7 @@
|
|
|
} else {
|
|
|
NSData *voiceData = [M4aToPcmHelper M4aToPcmWithUrl:[[NSURL alloc] initFileURLWithPath:path]];
|
|
|
if(voiceData == nil) {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
return;
|
|
|
}
|
|
|
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
|
|
|
@@ -108,17 +106,17 @@
|
|
|
[parser setDelegate:self];
|
|
|
[parser parserXml:strResults];
|
|
|
} else {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
} else {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)onCompleted:(IFlySpeechError *)errorCode {
|
|
|
if (errorCode.errorCode != 0) {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -135,20 +133,20 @@
|
|
|
|
|
|
-(void)onISEResultXmlParser:(NSXMLParser *)parser Error:(NSError*)error {
|
|
|
if (error.code != 0) {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-(void)onISEResultXmlParserResult:(ISEResult*)result {
|
|
|
if (result.is_rejected) {
|
|
|
- self.result([NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: [NSDictionary dictionaryWithObjectsAndKeys: self.index, @"index", [NSNull null], @"score", nil]];
|
|
|
} else {
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
[dic setValue:self.index forKey:@"index"];
|
|
|
[dic setValue:@(result.total_score) forKey:@"score"];
|
|
|
NSString* words = [ISEResultTools formatDetailsForLanguageEN: result.sentences];
|
|
|
[dic setValue:words forKey:@"words"];
|
|
|
- self.result(dic);
|
|
|
+ [_channel invokeMethod:@"evaluatorResult" arguments: dic];
|
|
|
}
|
|
|
}
|
|
|
|