Browse Source

fix(ble_service): 恢复扫描所有BLE设备的功能

refactor(agent_service): 优化语音识别初始化配置
将支持的语言列表改为使用变量,并添加配置存储
weicu
lxm 1 year ago
parent
commit
dd7dd56bfd
  1. 7
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift
  2. 10
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

7
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 azureSpeechKey: String = ""
private var azureSpeechRegion: String = "" private var azureSpeechRegion: String = ""
private var config: [String: Any] = [:]
private var isSpeaking: Bool = false private var isSpeaking: Bool = false
@ -136,6 +137,8 @@ class AgentServiceImpl: NSObject {
if isInitialized { return true } if isInitialized { return true }
// os_log("initialize: config=%{public}@", log: logger, type: .info, config) // os_log("initialize: config=%{public}@", log: logger, type: .info, config)
self.config = config
if let openaiApiKey = config["openaiApiKey"] as? String { if let openaiApiKey = config["openaiApiKey"] as? String {
self.apiKey = openaiApiKey self.apiKey = openaiApiKey
} else { } else {
@ -206,7 +209,7 @@ class AgentServiceImpl: NSObject {
guard let asrSuccess = azureAsrHelper?.initialize( guard let asrSuccess = azureAsrHelper?.initialize(
subscriptionKey: azureSpeechKey, subscriptionKey: azureSpeechKey,
region: azureSpeechRegion, region: azureSpeechRegion,
supportedLanguages: ["zh-CN"], supportedLanguages: supportedLanguages,
audioSourceType: .microphone audioSourceType: .microphone
), asrSuccess else { ), asrSuccess else {
sendError("初始化语音识别服务失败", code: "ASR_INIT_ERROR") sendError("初始化语音识别服务失败", code: "ASR_INIT_ERROR")
@ -863,7 +866,7 @@ private func processNavigationCard(_ cardNavigation: [String: Any]) {
} }
if languages.isEmpty { if languages.isEmpty {
os_log("语言列表为空,使用默认语言", log: logger, type: .warning) os_log("语言列表为空,使用默认语言", log: logger, type: .info)
return false return false
} }

10
local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

@ -230,13 +230,13 @@ private var cmdReplyType: UInt8 = 0
isScanning = true isScanning = true
// 移除服务UUID过滤,扫描所有设备 // 移除服务UUID过滤,扫描所有设备
// manager.scanForPeripherals(withServices: nil, options: [ manager.scanForPeripherals(withServices: nil, options: [
// CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
// ])
let serviceUUIDs = [BleConst.SERVICE_UUID]
manager.scanForPeripherals(withServices: serviceUUIDs, options: [
CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据 CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
]) ])
// let serviceUUIDs = [BleConst.SERVICE_UUID]
// manager.scanForPeripherals(withServices: serviceUUIDs, options: [
// CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
// ])
// os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout) // os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout)
// 设置扫描超时 // 设置扫描超时

Loading…
Cancel
Save