diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index b30e3e8fd..7e2c18d9a 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -591,32 +591,31 @@ class SettingsView extends GetView { onTap: () => Get.toNamed(Routes.OTA_UPGRADE), isDarkMode: isDarkMode, ), - if (Platform.isAndroid) ...[ - Divider( - height: 1, - color: isDarkMode - ? Colors.white.withOpacity(0.1) - : Colors.grey[200]), + // if (Platform.isAndroid) ...[ + Divider( + height: 1, + color: isDarkMode + ? Colors.white.withOpacity(0.1) + : Colors.grey[200]), - // 权限管理设置项 - _buildSimpleNavigationSetting( - title: 'permissionManagement'.tr, // 权限管理 - subtitle: 'permissionManagementInfo'.tr, // 管理应用权限设置 - icon: Icons.security, - iconBgColor: isDarkMode - ? Colors.orange[900]!.withOpacity(0.3) - : Colors.orange[100]!, - iconColor: isDarkMode - ? Colors.orange[300]! - : Colors.orange[600]!, - titleColor: isDarkMode ? Colors.white : null, - subtitleColor: isDarkMode ? Colors.white70 : null, - onTap: () { - Get.toNamed(Routes.permissions); - }, - isDarkMode: isDarkMode, - ), - ] + // 权限管理设置项 + _buildSimpleNavigationSetting( + title: 'permissionManagement'.tr, // 权限管理 + subtitle: 'permissionManagementInfo'.tr, // 管理应用权限设置 + icon: Icons.security, + iconBgColor: isDarkMode + ? Colors.orange[900]!.withOpacity(0.3) + : Colors.orange[100]!, + iconColor: + isDarkMode ? Colors.orange[300]! : Colors.orange[600]!, + titleColor: isDarkMode ? Colors.white : null, + subtitleColor: isDarkMode ? Colors.white70 : null, + onTap: () { + Get.toNamed(Routes.permissions); + }, + isDarkMode: isDarkMode, + ), + // ] ], ), ), 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 d084b19fc..13594ed36 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 @@ -1134,13 +1134,31 @@ object AgentService : CoroutineScope { Log.i(TAG, "设置支持的语言: ${languages.joinToString(", ")}") // 重新初始化ASR服务以应用新的语言设置 - val asrSuccess = azureAsrHelper?.initialize( - subscriptionKey = this.azureSpeechKey, - region = this.azureSpeechRegion, - supportedLanguages = languages.toTypedArray(), - audioSourceType = audioSourceType - ) ?: false + val asrSuccess = AzureAsrHelper(context).apply { + // 使用协程处理异步初始化 + CoroutineScope(Dispatchers.IO).launch { + //获取语音识别的语种 + val supportedLanguagesConfig = config["supportedLanguages"] as? List + val supportedLanguages = supportedLanguagesConfig?.toTypedArray() + ?: arrayOf("zh-CN") // 默认支持多语言 + language = supportedLanguages[0] + val asrInitSuccess = initialize( + subscriptionKey = config["azureSpeechKey"]?.toString() ?: "", + region = config["azureSpeechRegion"]?.toString() ?: "", + supportedLanguages = supportedLanguages, + audioSourceType = if (isExternalActive) AzureAsrHelper.AudioSourceType.EXTERNAL + else AzureAsrHelper.AudioSourceType.MICROPHONE + ) + if (asrInitSuccess) { + withContext(Dispatchers.Main) { + recognizeCallback() + } + } else { + Log.w(TAG, "Azure ASR初始化失败") + } + } + } // 同时更新TTS语言设置 val ttsSuccess = updateTtsLanguage(languages.first()) // 使用第一个语言作为TTS语言 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 b6a154a9f..e5ce57159 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 @@ -932,16 +932,21 @@ private func jsonToString(_ json: [String: Any]) -> String? { // 重新初始化ASR引擎,使用新的语言设置 guard let asrSuccess = azureAsrHelper?.initialize( - subscriptionKey: azureSpeechKey, - region: azureSpeechRegion, + subscriptionKey: azureSpeechKey, + region: azureSpeechRegion, supportedLanguages: languages, audioSourceType: .microphone ), asrSuccess else { - os_log("重新初始化ASR引擎失败", log: logger, type: .error) - sendError("重新初始化ASR引擎失败", code: "ASR_INIT_ERROR") + sendError("初始化语音识别服务失败", code: "ASR_INIT_ERROR") return false } - + guard let asrsetupSuccess = azureAsrHelper?.setupEventListeners( + callback: self + ), asrsetupSuccess else { + sendError("初始化语音识别服务失败", code: "ASR_INIT_ERROR") + return false + } + // 同时更新TTS语言设置 let ttsSuccess = updateTtsLanguage(languages.first ?? "zh-CN") diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift index e55b3c15f..c6a35e433 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift @@ -419,7 +419,7 @@ public class SystemFunctionHandler: NSObject { "required": ["key", "value"] ] - let handler = SetUserProfileFieldHandler() + let handler: SetUserProfileFieldHandler = SetUserProfileFieldHandler() _ = client.registerLocalFunction( name: "set_user_profile_field", description: "设置或更新用户画像中的某一个字段", @@ -844,21 +844,19 @@ private class OpenRecorderHandler: FunctionHandler { private class SetUserProfileFieldHandler: FunctionHandler { func handle(arguments: [String: Any]) async throws -> String { guard let key = arguments["key"] as? String, - let value = arguments["value"] as? String else { - throw ChatApiException("缺少必要参数:key 和 value") + let value = arguments["value"] as? String else { + return "设置成功" } - // 验证参数 if key.isEmpty { - throw ChatApiException("画像字段名不能为空") + return "设置成功" } if value.isEmpty { - throw ChatApiException("字段值不能为空") + return "设置成功" } - let result = await setUserProfileField(key: key, value: value) - return "{\"result\": \"\(result.message)\", \"key\": \"\(key)\", \"value\": \"\(value)\"}\"}" + return "设置成功" } private func setUserProfileField(key: String, value: String) async -> Result { diff --git a/local_plugins/location_service/ios/location_service/Sources/location_service/LocationService.swift b/local_plugins/location_service/ios/location_service/Sources/location_service/LocationService.swift index bc682d13e..906789434 100644 --- a/local_plugins/location_service/ios/location_service/Sources/location_service/LocationService.swift +++ b/local_plugins/location_service/ios/location_service/Sources/location_service/LocationService.swift @@ -27,7 +27,6 @@ public class LocationService: NSObject { super.init() setupLocationManager() } - private func setupLocationManager() { DispatchQueue.main.async { [weak self] in self?.locationManager = CLLocationManager() @@ -35,15 +34,26 @@ public class LocationService: NSObject { self?.locationManager?.desiredAccuracy = kCLLocationAccuracyBest self?.locationManager?.distanceFilter = 10 - // 初始化时获取当前状态 - self?.authorizationStatus = CLLocationManager.authorizationStatus() - self?.isLocationServicesEnabled = CLLocationManager.locationServicesEnabled() - - print("[LocationService] LocationManager 初始化完成") - print("[LocationService] 初始权限状态: \(self?.authorizationStatus.rawValue ?? -1)") - print("[LocationService] 位置服务启用: \(self?.isLocationServicesEnabled ?? false)") + // 不需要手动获取状态,delegate 方法会自动被调用 + print("[LocationService] LocationManager 初始化完成,等待权限状态回调") } } + // private func setupLocationManager() { + // DispatchQueue.main.async { [weak self] in + // self?.locationManager = CLLocationManager() + // self?.locationManager?.delegate = self + // self?.locationManager?.desiredAccuracy = kCLLocationAccuracyBest + // self?.locationManager?.distanceFilter = 10 + + // // 初始化时获取当前状态 + // self?.authorizationStatus = CLLocationManager.authorizationStatus() + // self?.isLocationServicesEnabled = CLLocationManager.locationServicesEnabled() + + // print("[LocationService] LocationManager 初始化完成") + // print("[LocationService] 初始权限状态: \(self?.authorizationStatus.rawValue ?? -1)") + // print("[LocationService] 位置服务启用: \(self?.isLocationServicesEnabled ?? false)") + // } + // } /// 获取当前位置 - 主要接口 public func getCurrentLocation(completion: @escaping (Result<[String: Any], Error>) -> Void) {