Browse Source

上传服务代码

weicu
liwei1dao 12 months ago
parent
commit
d59c967419
  1. 33
      lib/data/services/ble_manager.dart
  2. 4
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  3. 1
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt
  4. 2
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt

33
lib/data/services/ble_manager.dart

@ -6,6 +6,7 @@ import 'package:get_storage/get_storage.dart';
import 'package:get/get.dart';
import 'package:ble_service/ble_service.dart';
import 'package:agent_service/agent_service.dart';
import 'package:voitrans/data/models/appconfig_model.dart';
import '../../data/models/appconfig.dart';
import '../../core/utils/logger.dart';
@ -639,6 +640,35 @@ class BleManager extends GetxService {
}
}
String getDeviceName() {
if (deviceInfo.value != null) {
return deviceInfo.value!.name;
}
return "";
}
// 加载TTS偏好设置
Future<bool> _loadTtsInterrupe() async {
try {
if (!_storage.hasData("agent_tts_interrupe")) {
// 获取设备类型以确定检查策略
String deviceName = getDeviceName();
DBProduct? product = AppConfig.getproduct(deviceName);
if (deviceName != "" && product != null) {
// Logger.d('AgentController',
// 'liwe----------product $deviceName ${product.toJson()}');
return !product.iscontinuouschat!;
} else {
return false;
}
} else {
return _storage.read('agent_tts_interrupe') ?? false;
}
} catch (e) {
return false;
}
}
/// 启动BLE服务
Future<bool> startAgentService() async {
try {
@ -668,6 +698,8 @@ class BleManager extends GetxService {
// 从Flutter资源包中加载.mcp.json
final jsonData = AppConfig.mcpConfig();
Logger.info('启动BLE服务,musicServiceType: ${musicServiceType}');
final isTtsInterruptEnabled = await _loadTtsInterrupe();
// 根据APP语言动态配置语音识别语言
List<String> supportedLanguages = [];
try {
@ -737,6 +769,7 @@ class BleManager extends GetxService {
'supportedLanguages': supportedLanguages,
'musicServiceType': musicServiceType,
"navigationMode": navigationMode,
"isttsinterrupt": isTtsInterruptEnabled ? "true" : "false",
"callingTool": "callingTool".tr
};

4
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -203,11 +203,15 @@ object AgentService : CoroutineScope {
serverurl = config["serverurl"]?.toString() ?: "";
usertoken = config["usertoken"]?.toString() ?: "";
callingTool = config["callingTool"]?.toString() ?: "";
// 初始化上下文和服务
this.context = appContext.applicationContext
// 从 SharedPreferences 读取 _isInterrupt 状态
loadIsInterruptFromCache()
if (config["isttsinterrupt"] != null){
_isInterrupt.set(config["isttsinterrupt"]?.toString() == "true")
}
this.chatApiService = ChatApiService(context)
this.chatStorageHelper = ChatStorageHelper(context)

1
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt

@ -77,6 +77,7 @@ class AgentServicePlugin : FlutterPlugin, MethodCallHandler, EventChannel.Stream
config["usertoken"]?.toString()?.let { intent.putExtra("usertoken", it) }
config["musicServiceType"]?.toString()?.let { intent.putExtra("musicServiceType", it) }
config["navigationMode"]?.toString()?.let { intent.putExtra("navigationMode", it) }
config["isttsinterrupt"]?.toString()?.let { intent.putExtra("isttsinterrupt", it) }
config["callingTool"]?.toString()?.let { intent.putExtra("callingTool", it) }

2
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt

@ -571,6 +571,8 @@ private var companionManager: BleCompanionManager? = null
it.getStringExtra(KEY_MUSICSERVICE_TYPE)?.let { value -> config[KEY_MUSICSERVICE_TYPE] = value }
it.getStringExtra(APP_NAVIGATION_MODE)?.let { value -> config[APP_NAVIGATION_MODE] = value }
it.getStringExtra(APP_CALLING_TOOL)?.let { value -> config[APP_CALLING_TOOL] = value }
it.getStringExtra("isttsinterrupt")?.let { value -> config["isttsinterrupt"] = value }
// 提取 supportedLanguages 参数
it.getStringArrayListExtra(KEY_SUPPORTED_LANGUAGES)?.let { languages ->
if (languages.isNotEmpty()) {

Loading…
Cancel
Save