diff --git a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart index 7adfc296b..91e28e89d 100644 --- a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart +++ b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart @@ -1,4 +1,5 @@ import 'package:classic_bluetooth/classic_bluetooth.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:voitrans/data/models/appconfig_model.dart'; import '/routes/app_routes.dart'; import 'package:logger/web.dart'; @@ -214,10 +215,9 @@ class OtaUpgradeController extends GetxController { updatepackageaddress = product!.updatepackageaddress!; // 版本检查 - bool isUpdate = _isNewVersionAvailable(product.version!); + bool hasUpdate = _isNewVersionAvailable(product.version!); - - isUpdateAvailable.value = isUpdate; + isUpdateAvailable.value = hasUpdate; } catch (e) { // 统一错误处理 errorMessage.value = e.toString(); @@ -238,22 +238,36 @@ class OtaUpgradeController extends GetxController { } } - // 版本比较方法优化 - bool _isNewVersionAvailable(String latest) { + // 版本比较方法优化 - 支持升级和降级 + bool _isNewVersionAvailable(String latestVersion) { try { List currentParts = currentVersion.value .split('.') .map((e) => int.parse(e.trim())) .toList(); List latestParts = - latest.split('.').map((e) => int.parse(e.trim())).toList(); + latestVersion.split('.').map((e) => int.parse(e.trim())).toList(); + + // 确保两个版本号长度一致,短的用0补齐 + int maxLength = currentParts.length > latestParts.length + ? currentParts.length + : latestParts.length; - for (int i = 0; i < latestParts.length; i++) { - int current = (i < currentParts.length) ? currentParts[i] : 0; - if (latestParts[i] > current) return true; - if (latestParts[i] < current) return false; + while (currentParts.length < maxLength) { + currentParts.add(0); } - return false; + while (latestParts.length < maxLength) { + latestParts.add(0); + } + + // 比较每一段,只要有不同就返回true(支持升级和降级) + for (int i = 0; i < maxLength; i++) { + if (latestParts[i] != currentParts[i]) { + return true; // 版本不同,允许更新(升级或降级) + } + } + + return false; // 版本完全相同,无需更新 } catch (e) { Logger().d('版本比较错误: $e'); return false; @@ -654,7 +668,7 @@ class OtaUpgradeController extends GetxController { color: Colors.green[600], size: 28, ), - SizedBox(width: 12), + SizedBox(width: 12.w), Text( '升级成功', style: TextStyle( 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")