diff --git a/lib/data/services/ble_manager.dart b/lib/data/services/ble_manager.dart index ef78d9290..970cf6d5c 100644 --- a/lib/data/services/ble_manager.dart +++ b/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 _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 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 supportedLanguages = []; try { @@ -737,6 +769,7 @@ class BleManager extends GetxService { 'supportedLanguages': supportedLanguages, 'musicServiceType': musicServiceType, "navigationMode": navigationMode, + "isttsinterrupt": isTtsInterruptEnabled ? "true" : "false", "callingTool": "callingTool".tr }; diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index 5ef4e504f..2e241583c 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/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) diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt index 735672a7c..39edf4c8d 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt +++ b/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) } diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt index 08b079a23..e824eadcf 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt +++ b/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()) {