From e845d0052573b23a2e4db586dc027bd80be52f6c Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Mon, 13 Oct 2025 18:17:21 +0800 Subject: [PATCH] 11 --- .../Sources/agent_service/AgentServiceImpl.swift | 12 ++++++++++-- .../Sources/agent_service/AgentServicePlugin.swift | 5 ++++- 2 files changed, 14 insertions(+), 3 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 a5e25b57d..4ea14e8be 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 @@ -75,6 +75,9 @@ class AgentServiceImpl: NSObject { //是否保留最终结果 private var isKeepResult = true; + // 新增:是否在识别过程中被中断 + public var isInterrupt: Bool = true + var currsessionId: String = "" var language: String = "" private var serverurl = "" @@ -1664,7 +1667,9 @@ class ChatApiStreamCallback: StreamCallback { // 停止等待音效 agentService.audioPlayer?.stopAwaitSound() } - + if(agentService.isInterrupt){ + BleService.shared.closeCodec() + } if speakResponse && reply && broadcast && sessionid == agentService.currsessionId{ agentService.azureTtsHelper?.flushStream(sessionid:sessionid) @@ -1829,6 +1834,9 @@ extension AgentServiceImpl: TtsEventListener { MusicService.shared.reduceVolume() case .playbackCompleted: restartIdleCheck() + if(isInterrupt){ + BleService.shared.openEncoder() + } sendEvent(name: "playback_completed", data: ["status": "playback_completed"]) MusicService.shared.restoreVolume() case .synthesisCanceled: @@ -2132,7 +2140,7 @@ extension AgentServiceImpl: AzureAsrHelper.ContinuousRecognizeCallback { isStartingRecognition = false // 使用模式感知的空闲检测启动方法 startIdleCheckForMode(mode: currentRecognitionMode) - if (currentRecognitionMode == "ble_wakeup") { + if (currentRecognitionMode == "ble_wakeup") { audioPlayer?.playStartSound() } diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift index 08864a87f..6c7b0d36b 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift @@ -78,7 +78,10 @@ public class AgentServicePlugin: NSObject, FlutterPlugin { let mode = (call.arguments as? [String: Any])?["mode"] as? String ?? "normal" impl.startRecognition(mode: mode) result(true) - + case "isInterrupt": + impl.isInterrupt = !impl.isInterrupt + result(impl.isInterrupt) + case "recognizeCallback": impl.recognizeCallback() result(true)