Browse Source

chore: 添加调试日志以跟踪语音对话流程

添加开发者前缀的打印语句,便于调试语音对话的开始、结束和设备通信流程
newdev_shunjiawei
liwei1dao 9 months ago
parent
commit
e676882597
  1. 4
      lib/modules/agent/controllers/agent_controller.dart
  2. 4
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift
  3. 5
      local_plugins/agent_service/lib/agent_service.dart
  4. 22
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

4
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;

4
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()

5
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) {

22
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

Loading…
Cancel
Save