新增 logger 打印方法

This commit is contained in:
2025-09-30 14:48:12 +08:00
parent 1729d0f266
commit 07980fea87
12 changed files with 109 additions and 105 deletions

View File

@@ -27,7 +27,7 @@ class AIChatAssistantManager {
AIChatAssistantManager._internal() {
// 初始化代码
debugPrint('AIChatAssistant 单例创建');
Logger.i('AIChatAssistant 单例创建');
_commandCubit = AIChatCommandCubit();
}
@@ -82,7 +82,7 @@ class AIChatAssistantManager {
if (!file.existsSync()) {
final data = await rootBundle.load(assetPath);
await file.writeAsBytes(data.buffer.asUint8List(), flush: true);
debugPrint('Asset "$assetPath" extracted to "${file.path}"');
Logger.i('Asset "$assetPath" extracted to "${file.path}"');
}
return file.path;
}
@@ -92,11 +92,11 @@ class AIChatAssistantManager {
wakeWords: ['你好众众', '你好', '众众', '测试', '哈喽', '唤醒'], // 唤醒词列表
);
debugPrint('Starting Vosk Wakeword detection...');
Logger.i('Starting Vosk Wakeword detection...');
FlutterVoskWakeword.instance.start();
FlutterVoskWakeword.instance.recognitionStream.listen((event) {
debugPrint('Vosk Wakeword detected: ${event.text}');
Logger.i('Vosk Wakeword detected: ${event.text}');
_wakeWordDetected = true;
// 通知所有监听者
_wakeWordController.add(null);
@@ -137,9 +137,9 @@ class AIChatAssistantManager {
sensitivities: [0.6], // 可以调整灵敏度
);
await _porcupineManager?.start();
debugPrint("Porcupine manager started for wake-word detection.");
Logger.i("Porcupine manager started for wake-word detection.");
} on PorcupineException catch (e) {
debugPrint("Failed to init Porcupine: ${e.message}");
Logger.e("Failed to init Porcupine: ${e.message}");
_isWakeWordEnabled = false;
}
} else {
@@ -147,7 +147,7 @@ class AIChatAssistantManager {
await _porcupineManager?.delete();
_porcupineManager = null;
_wakeWordDetected = false; // 关闭时重置状态
debugPrint("Porcupine manager stopped and deleted.");
Logger.i("Porcupine manager stopped and deleted.");
}
}
@@ -156,7 +156,7 @@ class AIChatAssistantManager {
// 我们只用了一个关键词,所以索引总是 0
if (keywordIndex == 0) {
_wakeWordDetected = true;
debugPrint("Wake-word '众众' detected!");
Logger.i("Wake-word '众众' detected!");
// 通知所有监听者
_wakeWordController.add(null);
@@ -168,7 +168,7 @@ class AIChatAssistantManager {
}
void _porcupineErrorCallback(PorcupineException error) {
debugPrint("Porcupine error: ${error.message}");
Logger.e("Porcupine error: ${error.message}");
}
/// 释放资源
@@ -178,6 +178,6 @@ class AIChatAssistantManager {
_wakeWordController.close();
setWakeWordDetection(false); // 确保 Porcupine 停止并释放
FlutterVoskWakeword.instance.dispose();
debugPrint('AIChatAssistant 单例销毁');
Logger.i('AIChatAssistant 单例销毁');
}
}