diff --git a/lib/core/translations/language/en_us.dart b/lib/core/translations/language/en_us.dart index e84caa5af..3541bb74a 100644 --- a/lib/core/translations/language/en_us.dart +++ b/lib/core/translations/language/en_us.dart @@ -540,6 +540,7 @@ const Map enUS = { "loadMoreMessages": "Load more messages...", "loadFailedClickRetry": "Load failed, click to retry", "swipeUpForMore": "Swipe up for more", + "callingTool": "I'm helping you, please wait!", // 正在帮您,请稍等! // 预设提示词 "presetMusic": "Play some music", // Play some music diff --git a/lib/core/translations/language/zh_cn.dart b/lib/core/translations/language/zh_cn.dart index 63d24ebbb..cfee20434 100644 --- a/lib/core/translations/language/zh_cn.dart +++ b/lib/core/translations/language/zh_cn.dart @@ -511,7 +511,7 @@ const Map zhCN = { "loadMoreMessages": "加载更多消息...", "loadFailedClickRetry": "加载失败,点击重试", "swipeUpForMore": "向上滑动查看更多", - "callingTool": "正在调用工具!", + "callingTool": "正在帮您,请稍等!", // 预设提示词 "presetMusic": "来点音乐", // 来点音乐 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/lib/modules/agent/controllers/agent_controller.dart b/lib/modules/agent/controllers/agent_controller.dart index 1810d0b93..ad10e5d70 100644 --- a/lib/modules/agent/controllers/agent_controller.dart +++ b/lib/modules/agent/controllers/agent_controller.dart @@ -281,6 +281,7 @@ class AgentController extends GetxController with WidgetsBindingObserver { isTtsInterruptEnabled.value = _storage.read('agent_tts_interrupe') ?? false; } + await AgentService.isInterrupt(isTtsInterruptEnabled.value); } catch (e) { // 如果读取失败,使用默认值 Logger.e(TAG, '加载TTS偏好设置失败: $e'); diff --git a/lib/modules/pairing/controllers/pairing_controller.dart b/lib/modules/pairing/controllers/pairing_controller.dart index ba9ed71f4..dced5ab47 100644 --- a/lib/modules/pairing/controllers/pairing_controller.dart +++ b/lib/modules/pairing/controllers/pairing_controller.dart @@ -807,13 +807,13 @@ class PairingController extends GetxController with WidgetsBindingObserver { } } else { //未绑定设备 - _bleManager.clearPairedDevices(); + Logger.i(_tag, '验证时BLE状态: $currentBleState'); if (currentBleState == 2) { //已连接 清理 // BleConnectionState.connected Logger.i(_tag, 'BLE已连接,断开并清理缓存'); - + _bleManager.clearPairedDevices(); _bleManager.disconnect(); } } @@ -944,6 +944,11 @@ class PairingController extends GetxController with WidgetsBindingObserver { } } } + final currentBleState = await _bleManager.getConnectionState(); + if (currentBleState == 2) { + _bleManager.clearPairedDevices(); + _bleManager.disconnect(); + } await Future.delayed(Duration(seconds: 1)); } _bleManager.stopScan(); 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()) { diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift index e9a756ebf..25e740417 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift @@ -27,6 +27,10 @@ class AgentServiceImpl: NSObject { static let shared = AgentServiceImpl() + // UserDefaults 相关常量 + private let PREF_NAME = "agent_service_prefs" + private let KEY_IS_INTERRUPT = "is_interrupt" + private var listeners = [AgentServiceListener]() private let listenersLock = NSLock() @@ -252,6 +256,8 @@ class AgentServiceImpl: NSObject { if isInitialized { loadChatHistory() + // 从 UserDefaults 加载 isInterrupt 状态 + loadIsInterruptFromCache() } LocationService.shared.getCurrentLocation() { location in // self.locationInfo = location @@ -2238,4 +2244,25 @@ extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback { stopRequestedDuringStart = false stopIdleCheck() } + + // MARK: - isInterrupt 缓存方法 + + /** + * 从 UserDefaults 加载 isInterrupt 状态 + */ + private func loadIsInterruptFromCache() { + let userDefaults = UserDefaults.standard + let cachedValue = userDefaults.bool(forKey: KEY_IS_INTERRUPT) // 默认值为 false + isInterrupt = cachedValue + os_log("从缓存加载 isInterrupt 状态: %{public}@", log: logger, type: .info, String(isInterrupt)) + } + + /** + * 保存 isInterrupt 状态到 UserDefaults + */ + func saveIsInterruptToCache(_ isInterrupt: Bool) { + let userDefaults = UserDefaults.standard + userDefaults.set(isInterrupt, forKey: KEY_IS_INTERRUPT) + os_log("保存 isInterrupt 状态到缓存: %{public}@", log: logger, type: .info, String(isInterrupt)) + } } diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift index 6c7b0d36b..0877ab63e 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift @@ -79,8 +79,15 @@ public class AgentServicePlugin: NSObject, FlutterPlugin { impl.startRecognition(mode: mode) result(true) case "isInterrupt": - impl.isInterrupt = !impl.isInterrupt - result(impl.isInterrupt) + if let args = call.arguments as? [String: Any], + let isInterrupt = args["isinterrupt"] as? Bool { + impl.isInterrupt = isInterrupt + // 保存到 UserDefaults + impl.saveIsInterruptToCache(isInterrupt) + result(impl.isInterrupt) + } else { + result(FlutterError(code: "INVALID_ARGUMENTS", message: "isinterrupt 参数缺失或类型错误", details: nil)) + } case "recognizeCallback": impl.recognizeCallback()