From dd7dd56bfd7f8dc7bbcae48bd0392c84469dc81e Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Wed, 23 Jul 2025 16:53:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(ble=5Fservice):=20=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E6=89=80=E6=9C=89BLE=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor(agent_service): 优化语音识别初始化配置 将支持的语言列表改为使用变量,并添加配置存储 --- .../Sources/agent_service/AgentServiceImpl.swift | 7 +++++-- .../ble_service/Sources/ble_service/BleService.swift | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) 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 5b23a93fb..753dd87c4 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,7 @@ class AgentServiceImpl: NSObject { private var azureSpeechKey: String = "" private var azureSpeechRegion: String = "" + private var config: [String: Any] = [:] private var isSpeaking: Bool = false @@ -136,6 +137,8 @@ class AgentServiceImpl: NSObject { if isInitialized { return true } // os_log("initialize: config=%{public}@", log: logger, type: .info, config) + self.config = config + if let openaiApiKey = config["openaiApiKey"] as? String { self.apiKey = openaiApiKey } else { @@ -206,7 +209,7 @@ class AgentServiceImpl: NSObject { guard let asrSuccess = azureAsrHelper?.initialize( subscriptionKey: azureSpeechKey, region: azureSpeechRegion, - supportedLanguages: ["zh-CN"], + supportedLanguages: supportedLanguages, audioSourceType: .microphone ), asrSuccess else { sendError("初始化语音识别服务失败", code: "ASR_INIT_ERROR") @@ -863,7 +866,7 @@ private func processNavigationCard(_ cardNavigation: [String: Any]) { } if languages.isEmpty { - os_log("语言列表为空,使用默认语言", log: logger, type: .warning) + os_log("语言列表为空,使用默认语言", log: logger, type: .info) return false } diff --git a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift index b36c9c997..c54bacde2 100644 --- a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift +++ b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift @@ -230,13 +230,13 @@ private var cmdReplyType: UInt8 = 0 isScanning = true // 移除服务UUID过滤,扫描所有设备 - // manager.scanForPeripherals(withServices: nil, options: [ - // CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 - // ]) - let serviceUUIDs = [BleConst.SERVICE_UUID] - manager.scanForPeripherals(withServices: serviceUUIDs, options: [ + manager.scanForPeripherals(withServices: nil, options: [ CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 ]) + // let serviceUUIDs = [BleConst.SERVICE_UUID] + // manager.scanForPeripherals(withServices: serviceUUIDs, options: [ + // CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 + // ]) // os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout) // 设置扫描超时