提交 a68b90f8 作者: 王苏进

feat: 补充prepare evvientmen的

上级 e1f79b8e
......@@ -40,6 +40,9 @@ public class AivoicePlugin implements FlutterPlugin, MethodCallHandler, EventCha
} else if (call.method.equals("startOrStopEngine")) {
// 空实现
result.success(null);
} else if (call.method.equals("prepareEnvironment")) {
// 空实现
result.success(null);
} else {
result.notImplemented();
}
......
......@@ -21,10 +21,8 @@
eventChannelWithName:@"aivoice_plugin/events"
binaryMessenger:[registrar messenger]];
[eventChannel setStreamHandler:instance];
}
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
// 删除了 getPlatformVersion 方法的实现
......@@ -43,6 +41,10 @@
// BOOL arg = [NSNumber numberWithBool:call.arguments];
[self.voiceAsr startEngineBtnClicked];
result(nil);
} else if ([@"prepareEnvironment" isEqualToString:call.method]) {
[VoiceAsr prepareEnvironment:call.arguments];
result(nil);
} else {
result(FlutterMethodNotImplemented);
}
......@@ -72,8 +74,10 @@
return _voiceAsr;
}
- (void)onRecieve:(nonnull NSDictionary *)message {
[self sendMessageToFlutter:message];
}
@end
......@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDelegate:(id<VoiceAsrDelegate>)delegate;
+ (void)prepareEnvironment:(NSDictionary *)config;
- (void)initEngine;
- (void)uninitEngine;
......
......@@ -63,7 +63,19 @@
#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 {
[self setResultText:@""];
......
......@@ -25,6 +25,11 @@ class AivoicePlugin {
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');
......
......@@ -30,4 +30,9 @@ class MethodChannelAivoicePlugin extends AivoicePluginPlatform {
Future<void> startOrStopEngine(bool isBegin) async {
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 {
// 新增的 startOrStopEngine 方法
Future<void> startOrStopEngine(bool isBegin);
// 新增的 prepareEnvironment 方法
Future<void> prepareEnvironment(Map<String, dynamic> config);
}
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'aivoice_plugin_platform_interface.dart';
/// An implementation of [AivoicePluginPlatform] that uses method channels.
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
Future<void> initEngine(Map<String, dynamic> config) {
return _channel.invokeMethod<void>('initEngine', config);
Future<void> stopEngine() async {
await methodChannel.invokeMethod<void>('stopEngine');
}
@override
Future<void> stopEngine() {
return _channel.invokeMethod<void>('stopEngine');
Future<void> uninitEngine() async {
await methodChannel.invokeMethod<void>('uninitEngine');
}
@override
Future<void> uninitEngine() {
return _channel.invokeMethod<void>('uninitEngine');
Future<void> startOrStopEngine(bool isBegin) async {
await methodChannel.invokeMethod<void>('startOrStopEngine', {'isBegin': isBegin});
}
@override
Future<void> startOrStopEngine(bool isBegin) {
return _channel.invokeMethod<void>('startOrStopEngine', {'isBegin': isBegin});
Future<void> prepareEnvironment(Map<String, dynamic> config) async {
await methodChannel.invokeMethod<void>('prepareEnvironment', config);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论