提交 a68b90f8 作者: 王苏进

feat: 补充prepare evvientmen的

上级 e1f79b8e
...@@ -40,6 +40,9 @@ public class AivoicePlugin implements FlutterPlugin, MethodCallHandler, EventCha ...@@ -40,6 +40,9 @@ public class AivoicePlugin implements FlutterPlugin, MethodCallHandler, EventCha
} else if (call.method.equals("startOrStopEngine")) { } else if (call.method.equals("startOrStopEngine")) {
// 空实现 // 空实现
result.success(null); result.success(null);
} else if (call.method.equals("prepareEnvironment")) {
// 空实现
result.success(null);
} else { } else {
result.notImplemented(); result.notImplemented();
} }
......
...@@ -21,10 +21,8 @@ ...@@ -21,10 +21,8 @@
eventChannelWithName:@"aivoice_plugin/events" eventChannelWithName:@"aivoice_plugin/events"
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
[eventChannel setStreamHandler:instance]; [eventChannel setStreamHandler:instance];
}
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
// 删除了 getPlatformVersion 方法的实现 // 删除了 getPlatformVersion 方法的实现
...@@ -43,6 +41,10 @@ ...@@ -43,6 +41,10 @@
// BOOL arg = [NSNumber numberWithBool:call.arguments]; // BOOL arg = [NSNumber numberWithBool:call.arguments];
[self.voiceAsr startEngineBtnClicked]; [self.voiceAsr startEngineBtnClicked];
result(nil); result(nil);
} else if ([@"prepareEnvironment" isEqualToString:call.method]) {
[VoiceAsr prepareEnvironment:call.arguments];
result(nil);
} else { } else {
result(FlutterMethodNotImplemented); result(FlutterMethodNotImplemented);
} }
...@@ -72,8 +74,10 @@ ...@@ -72,8 +74,10 @@
return _voiceAsr; return _voiceAsr;
} }
- (void)onRecieve:(nonnull NSDictionary *)message { - (void)onRecieve:(nonnull NSDictionary *)message {
[self sendMessageToFlutter:message]; [self sendMessageToFlutter:message];
} }
@end @end
...@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDelegate:(id<VoiceAsrDelegate>)delegate; - (instancetype)initWithDelegate:(id<VoiceAsrDelegate>)delegate;
+ (void)prepareEnvironment:(NSDictionary *)config;
- (void)initEngine; - (void)initEngine;
- (void)uninitEngine; - (void)uninitEngine;
......
...@@ -63,7 +63,19 @@ ...@@ -63,7 +63,19 @@
#pragma mark - UI Actions #pragma mark - UI Actions
+ (void)prepareEnvironment:(NSDictionary *)config {
BOOL status = [SpeechEngine prepareEnvironment];
NSString *appId = config[@"appId"];
if (status) {
SpeechResourceManager *speechResourceManager = [SpeechResourceManager shareInstance];
[speechResourceManager setAppId:SDEF_APPID];
[speechResourceManager setAppVersion:@"1.0.0"];
// [speechResourceManager setDeviceId:self.deviceID];
[speechResourceManager setRootPath: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"models"]];
[speechResourceManager setOnlineModelEnable:YES];
[speechResourceManager setup];
}
}
- (void)startEngineBtnClicked { - (void)startEngineBtnClicked {
[self setResultText:@""]; [self setResultText:@""];
......
...@@ -25,6 +25,11 @@ class AivoicePlugin { ...@@ -25,6 +25,11 @@ class AivoicePlugin {
return AivoicePluginPlatform.instance.startOrStopEngine(isBegin); return AivoicePluginPlatform.instance.startOrStopEngine(isBegin);
} }
// 新增的 prepareEnvironment 方法
Future<void> prepareEnvironment(Map<String, dynamic> config) {
return AivoicePluginPlatform.instance.prepareEnvironment(config);
}
// 新增的监听方法 // 新增的监听方法
static const EventChannel _eventChannel = EventChannel('aivoice_plugin/events'); static const EventChannel _eventChannel = EventChannel('aivoice_plugin/events');
......
...@@ -30,4 +30,9 @@ class MethodChannelAivoicePlugin extends AivoicePluginPlatform { ...@@ -30,4 +30,9 @@ class MethodChannelAivoicePlugin extends AivoicePluginPlatform {
Future<void> startOrStopEngine(bool isBegin) async { Future<void> startOrStopEngine(bool isBegin) async {
await methodChannel.invokeMethod<void>('startOrStopEngine', {'isBegin': isBegin}); await methodChannel.invokeMethod<void>('startOrStopEngine', {'isBegin': isBegin});
} }
@override
Future<void> prepareEnvironment(Map<String, dynamic> config) async {
await methodChannel.invokeMethod<void>('prepareEnvironment', config);
}
} }
...@@ -36,4 +36,7 @@ abstract class AivoicePluginPlatform extends PlatformInterface { ...@@ -36,4 +36,7 @@ abstract class AivoicePluginPlatform extends PlatformInterface {
// 新增的 startOrStopEngine 方法 // 新增的 startOrStopEngine 方法
Future<void> startOrStopEngine(bool isBegin); Future<void> startOrStopEngine(bool isBegin);
// 新增的 prepareEnvironment 方法
Future<void> prepareEnvironment(Map<String, dynamic> config);
} }
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'aivoice_plugin_platform_interface.dart'; import 'aivoice_plugin_platform_interface.dart';
/// An implementation of [AivoicePluginPlatform] that uses method channels.
class MethodChannelAivoicePlugin extends AivoicePluginPlatform { class MethodChannelAivoicePlugin extends AivoicePluginPlatform {
final MethodChannel _channel = const MethodChannel('aivoice_plugin'); /// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('aivoice_plugin');
// 删除了 getPlatformVersion 方法
@override
Future<void> initEngine(Map<String, dynamic> config) async {
await methodChannel.invokeMethod<void>('initEngine', config);
}
@override @override
Future<void> initEngine(Map<String, dynamic> config) { Future<void> stopEngine() async {
return _channel.invokeMethod<void>('initEngine', config); await methodChannel.invokeMethod<void>('stopEngine');
} }
@override @override
Future<void> stopEngine() { Future<void> uninitEngine() async {
return _channel.invokeMethod<void>('stopEngine'); await methodChannel.invokeMethod<void>('uninitEngine');
} }
@override @override
Future<void> uninitEngine() { Future<void> startOrStopEngine(bool isBegin) async {
return _channel.invokeMethod<void>('uninitEngine'); await methodChannel.invokeMethod<void>('startOrStopEngine', {'isBegin': isBegin});
} }
@override @override
Future<void> startOrStopEngine(bool isBegin) { Future<void> prepareEnvironment(Map<String, dynamic> config) async {
return _channel.invokeMethod<void>('startOrStopEngine', {'isBegin': isBegin}); await methodChannel.invokeMethod<void>('prepareEnvironment', config);
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论