Browse Source

fix(agent_service): 设置默认识别模式为normal并移除冗余日志

移除AgentServiceImpl中的冗余日志输出
在AgentServicePlugin中设置currentRecognitionMode默认值
添加AzureTtsHelper的调试日志用于跟踪识别模式
weicu
liwei1dao 9 months ago
parent
commit
fc2afcecd5
  1. 15
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift
  2. 1
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift
  3. 4
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift

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

@ -713,10 +713,7 @@ class AgentServiceImpl: NSObject {
_ = chatApiService?.cancelCurrentStream() _ = chatApiService?.cancelCurrentStream()
} }
stopTts() stopTts()
currentRecognitionMode = "normal"
os_log("开始处理文本输入", log: logger, type: .info)
processWithChatApiService(sessionid: sessionid, text: text, speakResponse: speakResponse) processWithChatApiService(sessionid: sessionid, text: text, speakResponse: speakResponse)
return true return true
} }
@ -749,7 +746,7 @@ class AgentServiceImpl: NSObject {
stopTts(); stopTts();
isAiStreaming = true isAiStreaming = true
os_log("设置AI流式状态为true", log: logger, type: .info) // os_log("设置AI流式状态为true", log: logger, type: .info)
var messages: [[String: Any]] = [] var messages: [[String: Any]] = []
@ -766,17 +763,17 @@ class AgentServiceImpl: NSObject {
// print("用户画像数据: \(info)") // print("用户画像数据: \(info)")
let _systemPrompt = fillTemplate(systemPrompt, with: info) let _systemPrompt = fillTemplate(systemPrompt, with: info)
print("替换后的系统提示词: \(_systemPrompt)") // print("替换后的系统提示词: \(_systemPrompt)")
messages.append(chatApiService.createSystemMessage(content: _systemPrompt)) messages.append(chatApiService.createSystemMessage(content: _systemPrompt))
os_log("添加系统提示消息", log: logger, type: .info) // os_log("添加系统提示消息", log: logger, type: .info)
} }
messages.append(contentsOf: chatHistory) 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) messages.append(userMessage)
os_log("添加用户消息", log: logger, type: .info) // os_log("添加用户消息", log: logger, type: .info)
// 保存用户消息 // 保存用户消息
self.chatStorageHelper.saveMessage( self.chatStorageHelper.saveMessage(

1
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 let speakResponse = arguments["speakResponse"] as? Bool ?? false
impl.currentRecognitionMode = "normal"
let success = impl.processTextInput(sessionid: sessionid,text, speakResponse: speakResponse) let success = impl.processTextInput(sessionid: sessionid,text, speakResponse: speakResponse)
result(success) result(success)

4
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 { public func setPhoneCallMode(mod: String) -> Bool {
// os_log("[liwei] AzureTtsHelper: setPhoneCallMode: %{public}@", log: log, type: .debug, mod)
self.previousRecognitionMode = self.currentRecognitionMode self.previousRecognitionMode = self.currentRecognitionMode
self.currentRecognitionMode = mod self.currentRecognitionMode = mod
self.isHeadphones = detectHeadphonesOutput() self.isHeadphones = detectHeadphonesOutput()
@ -1416,7 +1417,7 @@ private func applyAudioSessionForTTS() -> Bool {
var desiredOptions: AVAudioSession.CategoryOptions = [] var desiredOptions: AVAudioSession.CategoryOptions = []
let isHeadphonesConnected = outputs.contains(where: { $0.portType == .headphones || $0.portType == .headsetMic || $0.portType == .bluetoothA2DP }) 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" { if self.currentRecognitionMode == "phone_call" || self.currentRecognitionMode == "push_to_talk" {
desiredCategory = .playAndRecord desiredCategory = .playAndRecord
if isHeadphonesConnected { if isHeadphonesConnected {
@ -1567,6 +1568,7 @@ private func isTelephonyActive() -> Bool {
/// - 外部音频播放时启用 spoken audio 策略,确保能在 A2DP 上播放 /// - 外部音频播放时启用 spoken audio 策略,确保能在 A2DP 上播放
/// - 仅当类别或模式发生变化时才 setCategory,降低 AVAudioSessionRouteChangeReason.categoryChange 的触发概率 /// - 仅当类别或模式发生变化时才 setCategory,降低 AVAudioSessionRouteChangeReason.categoryChange 的触发概率
private func safeConfigureAudioSessionForTTS() { private func safeConfigureAudioSessionForTTS() {
os_log("[liwei] AzureTtsHelper: safeConfigureAudioSessionForTTS - recognitionMode: %{public}@", log: log, type: .debug, currentRecognitionMode)
// 使用异步,避免串行队列重入自锁 // 使用异步,避免串行队列重入自锁
audioSessionQueue.async { [weak self] in audioSessionQueue.async { [weak self] in
guard let self = self else { return } guard let self = self else { return }

Loading…
Cancel
Save