Browse Source

fix(语音识别): 修复从蓝牙唤醒模式切换时编码器未关闭的问题

在 startRecognition 方法中,当上一次识别模式为 ble_wakeup 而当前模式不是 ble_wakeup 时,主动调用 BleService.shared.closeCodec() 关闭蓝牙编码器,避免资源泄漏和状态不一致。同时移除冗余的 AudioSessionHub 调用并调整代码格式。
weicu
liwei1dao 9 months ago
parent
commit
a032223676
  1. 13
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

13
local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

@ -103,6 +103,7 @@ class AgentServiceImpl: NSObject {
private let maxIdleSeconds: TimeInterval = 5 private let maxIdleSeconds: TimeInterval = 5
var micCapture: MicrophoneCapture! var micCapture: MicrophoneCapture!
// 语音识别模式 // 语音识别模式
private var lastRecognitionMode: String = "normal"
public var currentRecognitionMode: String = "normal" public var currentRecognitionMode: String = "normal"
// 识别结果 // 识别结果
private var recognitionResult = "" private var recognitionResult = ""
@ -508,6 +509,11 @@ class AgentServiceImpl: NSObject {
return false return false
} }
} }
lastRecognitionMode = currentRecognitionMode
if (lastRecognitionMode == "ble_wakeup" && mode != "ble_wakeup"){//之前是唤醒模式,现在不是唤醒模式
os_log("liwei------- 关闭唤醒通道", log: logger, type: .info)
BleService.shared.closeCodec()
}
stopRecognition() stopRecognition()
if isAiStreaming { if isAiStreaming {
isAiStreaming = false isAiStreaming = false
@ -529,13 +535,6 @@ class AgentServiceImpl: NSObject {
os_log("liwei--------------- 设置语音识别模式: %{public}@", log: logger, type: .info, mode) os_log("liwei--------------- 设置语音识别模式: %{public}@", log: logger, type: .info, mode)
let audioSourceType: AzureAsrHelper.AudioSourceType = useBle ? .external : .microphone let audioSourceType: AzureAsrHelper.AudioSourceType = useBle ? .external : .microphone
if useBle {
// AudioSessionHub.shared.begin(.playback)
} else {
//AudioSessionHub.shared.begin(.voice)
}
// 新增:标记为"启动中",用于允许 stop 在启动未完成时也能生效 // 新增:标记为"启动中",用于允许 stop 在启动未完成时也能生效
isStartingRecognition = true isStartingRecognition = true

Loading…
Cancel
Save