From 5d967375a27f8b1ce3b02f66faac7f7c4a6693ed Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Mon, 26 Jan 2026 20:46:31 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(=E8=AF=AD=E9=9F=B3=E8=AF=86?= =?UTF-8?q?=E5=88=AB):=20=E4=BF=AE=E5=A4=8D=E4=BB=8E=E8=93=9D=E7=89=99?= =?UTF-8?q?=E5=94=A4=E9=86=92=E6=A8=A1=E5=BC=8F=E5=88=87=E6=8D=A2=E6=97=B6?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E5=99=A8=E6=9C=AA=E5=85=B3=E9=97=AD=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e3f0f9bccd748b875005180502c6401085001478. --- .../agent_service/AgentServiceImpl.swift | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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 8e3bf9d4a..1f1be4a8f 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 @@ -103,7 +103,6 @@ class AgentServiceImpl: NSObject { private let maxIdleSeconds: TimeInterval = 5 var micCapture: MicrophoneCapture! // 语音识别模式 - private var lastRecognitionMode: String = "normal" public var currentRecognitionMode: String = "normal" // 识别结果 private var recognitionResult = "" @@ -489,7 +488,7 @@ class AgentServiceImpl: NSObject { startIdleCheckForMode(mode: currentRecognitionMode) } } - func startRecognition(useBle: Bool = false, mode: String = "normal") -> Bool { + func startRecognition(useBle: Bool = false, mode: String = "normal") -> Bool { // 接收到唤醒信号,打开编码器 (设备侧) print("ai启动语音\(useBle))") var openResult = false // 添加openResult变量定义 @@ -508,12 +507,7 @@ class AgentServiceImpl: NSObject { sendError("无麦克风权限", code: "PERMISSION_DENIED") return false } - } - lastRecognitionMode = currentRecognitionMode - if (lastRecognitionMode == "ble_wakeup" && mode != "ble_wakeup"){//之前是唤醒模式,现在不是唤醒模式 - os_log("liwei------- 关闭唤醒通道", log: logger, type: .info) - BleService.shared.closeCodec() - } + } stopRecognition() if isAiStreaming { isAiStreaming = false @@ -529,12 +523,19 @@ class AgentServiceImpl: NSObject { if MusicService.shared.isPlaying { MusicService.shared.pause() } - + // 设置当前识别模式 currentRecognitionMode = mode os_log("liwei--------------- 设置语音识别模式: %{public}@", log: logger, type: .info, mode) let audioSourceType: AzureAsrHelper.AudioSourceType = useBle ? .external : .microphone + + if useBle { + // AudioSessionHub.shared.begin(.playback) + } else { + //AudioSessionHub.shared.begin(.voice) + } + // 新增:标记为"启动中",用于允许 stop 在启动未完成时也能生效 isStartingRecognition = true @@ -550,8 +551,8 @@ class AgentServiceImpl: NSObject { return false } if(useBle){ - isKeepResult = true - } + isKeepResult = true + } // 根据模式启动相应的空闲检测(此处 guard isRecognizing,会在 onSessionStarted 中再次启动) startIdleCheckForMode(mode: mode)