From ae4d282aaf41e6326b164beea9ab31f114dd94f2 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 22 Jan 2026 21:47:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent=5Fservice):=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=AF=86=E5=88=AB=E6=A8=A1=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?normal=E5=B9=B6=E7=A7=BB=E9=99=A4=E5=86=97=E4=BD=99=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除AgentServiceImpl中的冗余日志输出 在AgentServicePlugin中设置currentRecognitionMode默认值 添加AzureTtsHelper的调试日志用于跟踪识别模式 --- .../Sources/agent_service/AgentServiceImpl.swift | 15 ++++++--------- .../agent_service/AgentServicePlugin.swift | 1 + .../Sources/azure_speech/AzureTtsHelper.swift | 4 +++- 3 files changed, 10 insertions(+), 10 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 bbe269dbc..b0a7ee5f0 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 @@ -713,10 +713,7 @@ class AgentServiceImpl: NSObject { _ = chatApiService?.cancelCurrentStream() } stopTts() - currentRecognitionMode = "normal" - - os_log("开始处理文本输入", log: logger, type: .info) - + processWithChatApiService(sessionid: sessionid, text: text, speakResponse: speakResponse) return true } @@ -749,7 +746,7 @@ class AgentServiceImpl: NSObject { stopTts(); isAiStreaming = true - os_log("设置AI流式状态为true", log: logger, type: .info) + // os_log("设置AI流式状态为true", log: logger, type: .info) var messages: [[String: Any]] = [] @@ -766,17 +763,17 @@ class AgentServiceImpl: NSObject { // print("用户画像数据: \(info)") let _systemPrompt = fillTemplate(systemPrompt, with: info) - print("替换后的系统提示词: \(_systemPrompt)") + // print("替换后的系统提示词: \(_systemPrompt)") messages.append(chatApiService.createSystemMessage(content: _systemPrompt)) - os_log("添加系统提示消息", log: logger, type: .info) + // os_log("添加系统提示消息", log: logger, type: .info) } messages.append(contentsOf: chatHistory) - os_log("添加历史消息: %d条", log: logger, type: .info, chatHistory.count) + // os_log("添加历史消息: %d条", log: logger, type: .info, chatHistory.count) messages.append(userMessage) - os_log("添加用户消息", log: logger, type: .info) + // os_log("添加用户消息", log: logger, type: .info) // 保存用户消息 self.chatStorageHelper.saveMessage( 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 e8a5d6209..77d9085d9 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 @@ -121,6 +121,7 @@ public class AgentServicePlugin: NSObject, FlutterPlugin { } let speakResponse = arguments["speakResponse"] as? Bool ?? false + impl.currentRecognitionMode = "normal" let success = impl.processTextInput(sessionid: sessionid,text, speakResponse: speakResponse) result(success) diff --git a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift index cd66fb76d..6734d418f 100644 --- a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift +++ b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift @@ -416,6 +416,7 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { public func setPhoneCallMode(mod: String) -> Bool { + // os_log("[liwei] AzureTtsHelper: setPhoneCallMode: %{public}@", log: log, type: .debug, mod) self.previousRecognitionMode = self.currentRecognitionMode self.currentRecognitionMode = mod self.isHeadphones = detectHeadphonesOutput() @@ -1416,7 +1417,7 @@ private func applyAudioSessionForTTS() -> Bool { var desiredOptions: AVAudioSession.CategoryOptions = [] let isHeadphonesConnected = outputs.contains(where: { $0.portType == .headphones || $0.portType == .headsetMic || $0.portType == .bluetoothA2DP }) - + os_log("[liwei] AzureTtsHelper: applyAudioSessionForTTS: %{public}@", log: self.log, type: .debug, self.currentRecognitionMode) if self.currentRecognitionMode == "phone_call" || self.currentRecognitionMode == "push_to_talk" { desiredCategory = .playAndRecord if isHeadphonesConnected { @@ -1567,6 +1568,7 @@ private func isTelephonyActive() -> Bool { /// - 外部音频播放时启用 spoken audio 策略,确保能在 A2DP 上播放 /// - 仅当类别或模式发生变化时才 setCategory,降低 AVAudioSessionRouteChangeReason.categoryChange 的触发概率 private func safeConfigureAudioSessionForTTS() { + os_log("[liwei] AzureTtsHelper: safeConfigureAudioSessionForTTS - recognitionMode: %{public}@", log: log, type: .debug, currentRecognitionMode) // 使用异步,避免串行队列重入自锁 audioSessionQueue.async { [weak self] in guard let self = self else { return }