From e6768825979812e63de50a02dca1a5000759a121 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 27 Jan 2026 17:41:41 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BB=A5=E8=B7=9F=E8=B8=AA=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加开发者前缀的打印语句,便于调试语音对话的开始、结束和设备通信流程 --- .../agent/controllers/agent_controller.dart | 4 ++-- .../agent_service/AgentServicePlugin.swift | 4 ++-- .../agent_service/lib/agent_service.dart | 5 +++-- .../Sources/ble_service/BleService.swift | 22 +++++++++---------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/modules/agent/controllers/agent_controller.dart b/lib/modules/agent/controllers/agent_controller.dart index c76ab1c54..f16dd703d 100644 --- a/lib/modules/agent/controllers/agent_controller.dart +++ b/lib/modules/agent/controllers/agent_controller.dart @@ -1880,7 +1880,7 @@ class AgentController extends GetxController with WidgetsBindingObserver { // 开始按住说话 void startPushToTalk() async { - Logger.i(TAG, '🎤 开始按住说话'); + print('liwei--------- 🎤 开始按住说话'); // 只有在语音模式且按住说话模式下才能按住说话 if (isTextInputMode.value) return; @@ -1898,7 +1898,7 @@ class AgentController extends GetxController with WidgetsBindingObserver { // 结束按住说话 void endPushToTalk() async { - Logger.i(TAG, '🎤 结束按住说话'); + print('liwei----------🎤 结束按住说话'); // 如果不在按住说话状态,直接返回 if (!isPushToTalkActive.value) return; 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 77d9085d9..8963009e1 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 @@ -74,7 +74,7 @@ public class AgentServicePlugin: NSObject, FlutterPlugin { result(true) return } - print("startConversation") + print("liwei----------AgentServicePlugin startConversation") let mode = (call.arguments as? [String: Any])?["mode"] as? String ?? "normal" impl.startRecognition(mode: mode) result(true) @@ -99,7 +99,7 @@ public class AgentServicePlugin: NSObject, FlutterPlugin { result(true) return } - print("stopConversation") + print("liwei-------AgentServicePlugin stopConversation") // 关闭编码器 (设备侧) BleService.shared.closeCodec() impl.stopRecognition() diff --git a/local_plugins/agent_service/lib/agent_service.dart b/local_plugins/agent_service/lib/agent_service.dart index 3ddbed06d..92dd7cafa 100644 --- a/local_plugins/agent_service/lib/agent_service.dart +++ b/local_plugins/agent_service/lib/agent_service.dart @@ -265,8 +265,8 @@ class AgentService { try { // 在启动新对话前,确保之前的对话已完全停止 // 这不仅可以清理状态,还能避免因快速切换导致的资源冲突 - await stopConversation(); - + // await stopConversation(); + print('liwei--------- view startConversation'); final bool result = await _channel.invokeMethod('startConversation', { 'mode': mode, }); @@ -337,6 +337,7 @@ class AgentService { // 即使频繁调用,Native 层也能处理(我们已经修复了 Native 层的并发问题)。 try { + print('liwei--------- view stopConversation'); final bool result = await _channel.invokeMethod('stopConversation'); return result; } on PlatformException catch (e) { diff --git a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift index 0691e1e88..1ec345635 100644 --- a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift +++ b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift @@ -834,7 +834,7 @@ private var cmdReplyType: UInt8 = 0 private func sendCommand(_ cmd: UInt8, data: Data = Data()) -> Bool { guard let characteristic = writeCharacteristic, connectionState == BleConst.STATE_CONNECTED else { - os_log("发送命令失败: 设备未连接", log: logger, type: .error) + os_log("liwei---- 发送命令失败: 设备未连接", log: logger, type: .error) return false } @@ -862,7 +862,7 @@ private var cmdReplyType: UInt8 = 0 if !data.isEmpty { dataHexString = data.map { String(format: "0x%02X", $0) }.joined(separator: ", ") } - os_log("发送命令: CMD=0x%02X, 长度=%d, 数据=[%@], CRC=0x%02X", + os_log("liwei---- 发送命令: CMD=0x%02X, 长度=%d, 数据=[%@], CRC=0x%02X", log: logger, type: .debug, cmd, cmdLength, dataHexString, crc) @@ -881,7 +881,7 @@ private var cmdReplyType: UInt8 = 0 return true } catch { - os_log("发送命令异常: %@", log: logger, type: .error, error.localizedDescription) + os_log("liwei---- 发送命令异常: %@", log: logger, type: .error, error.localizedDescription) return false } } @@ -929,19 +929,17 @@ private var cmdReplyType: UInt8 = 0 /// - Returns: 可用于追加写入的 RecordingFile 实例 /// - Throws: 不抛出;若创建文件失败将导致后续写入无效 private func ensureOpusRecordingStarted(fileName: String) -> RecordingFile { - if recordingFile == nil { - let recorder = RecordingFile() + let recorder = recordingFile ?? RecordingFile() + if recorder.fileName.isEmpty { recorder.fileName = fileName - recordingFile = recorder - } else if (recordingFile?.fileName.isEmpty ?? true) { - recordingFile?.fileName = fileName } - if recordingFile?.isRecording() != true { - recordingFile?.createFile() + if !recorder.isRecording() { + recorder.createFile() } - return recordingFile! + recordingFile = recorder + return recorder } /// 停止并释放 Opus 落盘资源 @@ -1010,7 +1008,7 @@ private var cmdReplyType: UInt8 = 0 // 记录响应详情 var hexString = data.map { String(format: "0x%02X", $0) }.joined(separator: ", ") - os_log("收到设备响应: %@", log: logger, type: .debug, hexString) + os_log("liwei---- 收到设备响应: %@", log: logger, type: .debug, hexString) // 检查数据长度(与 Android 统一失败判定保持一致) if data.count != Int(length) + 4 { // 帧头 + 命令 + 长度 + 数据 + CRC