Browse Source

上传优化代码

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
cb86be45f3
  1. 18
      lib/modules/agent/controllers/agent_controller.dart
  2. 30
      lib/modules/agent/views/message_bubble.dart
  3. 20
      lib/modules/home/controllers/home_controller.dart
  4. 3
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift
  5. 3
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/IntegratedSpeechTranslationService.swift
  6. 26
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

18
lib/modules/agent/controllers/agent_controller.dart

@ -318,8 +318,8 @@ class AgentController extends GetxController {
// 更新分页状态 // 更新分页状态
currentPage.value = 1; currentPage.value = 1;
hasMoreMessages.value = result.totalPages > 1; hasMoreMessages.value = result.totalPages > 1;
print( // print(
'liwei-------------读取历史记录 ${AppDir.value}${historyMessages[0].imagePath}'); // 'liwei-------------读取历史记录 ${AppDir.value}${historyMessages[0].imagePath}');
Logger.i(TAG, Logger.i(TAG,
'成功加载 ${historyMessages.length} 条聊天记录,总页数: ${result.totalPages}'); '成功加载 ${historyMessages.length} 条聊天记录,总页数: ${result.totalPages}');
_logMessageDetails(historyMessages); _logMessageDetails(historyMessages);
@ -800,12 +800,14 @@ class AgentController extends GetxController {
["card_navigation"]["start"] as String; ["card_navigation"]["start"] as String;
final end = metaResult["maps_route_navigation"] final end = metaResult["maps_route_navigation"]
["card_navigation"]["end"] as String; ["card_navigation"]["end"] as String;
// Logger.i(TAG, 'liwei-------- 打开导航页面: $start $end '); final items = metaResult['items'];
Future.delayed(Duration(seconds: 2), () { if (items != null) {
// Logger.i(TAG, 'liwei-------- 打开导航页面: $start $end '); Future.delayed(Duration(seconds: 2), () {
// 2秒后执行的代码 // Logger.i(TAG, 'liwei-------- 打开导航页面: $start $end ');
openNavigation(start, end, ""); // 2秒后执行的代码
}); openNavigation(start, end, "");
});
}
} }
} }
} }

30
lib/modules/agent/views/message_bubble.dart

@ -296,20 +296,22 @@ class MessageBubble extends GetView<AgentController> {
final start = card_navigation['start'] as String? ?? ''; final start = card_navigation['start'] as String? ?? '';
final end = card_navigation['end'] as String? ?? ''; final end = card_navigation['end'] as String? ?? '';
final destination = card_navigation['destination'] as String? ?? ''; final destination = card_navigation['destination'] as String? ?? '';
final rawList = card_navigation['items'] as List? ?? []; final rawList = card_navigation['items'] as List? ?? null;
final list = if (rawList != null) {
rawList.map((e) => Map<String, dynamic>.from(e)).toList(); final list =
final rawNavigation = card_navigation['navigation']; rawList.map((e) => Map<String, dynamic>.from(e)).toList();
final Map<String, dynamic>? navigation = final rawNavigation = card_navigation['navigation'];
rawNavigation is Map<String, dynamic> ? rawNavigation : null; final Map<String, dynamic>? navigation =
print("导航实时数据 ${rawNavigation}"); rawNavigation is Map<String, dynamic> ? rawNavigation : null;
// 导航 // print("导航实时数据 ${rawNavigation}");
return navigationCard(context, // 导航
start: start, return navigationCard(context,
end: end, start: start,
destination: destination, end: end,
modes: list, destination: destination,
navigation: navigation); modes: list,
navigation: navigation);
}
} }
} }

20
lib/modules/home/controllers/home_controller.dart

@ -1,4 +1,3 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'dart:async'; import 'dart:async';
import '../../../data/services/novice_guide_service.dart'; import '../../../data/services/novice_guide_service.dart';
@ -69,7 +68,7 @@ class HomeController extends GetxController {
super.onInit(); super.onInit();
_otaCheckService = Get.find<OtaCheckService>(); _otaCheckService = Get.find<OtaCheckService>();
_initWithCachedInfo(); _initWithCachedInfo();
_startBatteryRefreshTimer(); // 启动电池信息定时刷新 // _startBatteryRefreshTimer(); // 启动电池信息定时刷新
} }
@override @override
@ -158,12 +157,12 @@ class HomeController extends GetxController {
}); });
} }
// 根据连接状态控制定时器 // 根据连接状态控制定时器
if (isNowConnected) { // if (isNowConnected) {
_startBatteryRefreshTimer(); // 连接时启动定时器 // _startBatteryRefreshTimer(); // 连接时启动定时器
} else { // } else {
_stopBatteryRefreshTimer(); // 断开时停止定时器 // _stopBatteryRefreshTimer(); // 断开时停止定时器
// 注意:不再重置OTA检查状态,因为现在由全局服务管理 // // 注意:不再重置OTA检查状态,因为现在由全局服务管理
} // }
} }
update(); update();
@ -351,7 +350,8 @@ class HomeController extends GetxController {
Logger.d(_tag, 'OTA检查状态: $status'); Logger.d(_tag, 'OTA检查状态: $status');
// 使用全局OTA检查服务执行检查 // 使用全局OTA检查服务执行检查
final success = await _otaCheckService.performOtaCheck(_isFullyConnected.value); final success =
await _otaCheckService.performOtaCheck(_isFullyConnected.value);
if (success) { if (success) {
Logger.d(_tag, 'OTA检查已成功执行'); Logger.d(_tag, 'OTA检查已成功执行');
@ -365,6 +365,4 @@ class HomeController extends GetxController {
Map<String, dynamic> getOtaCheckStatus() { Map<String, dynamic> getOtaCheckStatus() {
return _otaCheckService.getCheckStatus(); return _otaCheckService.getCheckStatus();
} }
} }

3
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift

@ -337,6 +337,7 @@ private func sendAstEvent(_ event: [String: Any]) {
os_log("音频流未初始化", type: .error) os_log("音频流未初始化", type: .error)
return return
} }
print("liwei----------外部音频推送:\(audioBytes.data.count)")
audioStream.saveAudioDataTo(data: audioBytes.data) audioStream.saveAudioDataTo(data: audioBytes.data)
@ -901,6 +902,7 @@ extension AzureSpeechPlugin: BleService.Callback {
os_log("音频流未初始化", type: .error) os_log("音频流未初始化", type: .error)
return return
} }
print("liwei--------------接收到音频数据回调")
audioStream.saveAudioDataTo(data: data) audioStream.saveAudioDataTo(data: data)
} }
@ -912,6 +914,7 @@ extension AzureSpeechPlugin: BleService.Callback {
os_log("音频流未初始化", type: .error) os_log("音频流未初始化", type: .error)
return return
} }
print("liwei--------------接收到音频数据回调1")
audioStream.saveAudioDataTo(data: data) audioStream.saveAudioDataTo(data: data)
} }

3
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/IntegratedSpeechTranslationService.swift

@ -882,6 +882,7 @@ import os.log
* 推送外部音频数据 * 推送外部音频数据
*/ */
public func pushAudioData(audioData: Data) { public func pushAudioData(audioData: Data) {
audioProcessor?.saveAudioDataTo(data:audioData) audioProcessor?.saveAudioDataTo(data:audioData)
} }
@ -968,4 +969,4 @@ func withTimeout<T>(_ timeout: TimeInterval, operation: @escaping () async throw
group.cancelAll() group.cancelAll()
return result return result
} }
} }

26
local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

@ -223,21 +223,29 @@ public class SimpleAudioReceiver: NSObject {
*/ */
private func runMicrophoneCapture() { private func runMicrophoneCapture() {
do { do {
print("liwei------------启动麦克风权限")
// 【新增】首先配置音频会话 // 【新增】首先配置音频会话
try audioSession.setCategory( try audioSession.setCategory(
.playAndRecord, .playAndRecord,
mode: .videoChat, mode: .videoChat,
options: [.defaultToSpeaker,.allowBluetooth,.mixWithOthers] options: [
.defaultToSpeaker,
.allowBluetooth,
.mixWithOthers,
.duckOthers
]
) )
// 【新增】请求麦克风权限(如果尚未授权) // 【新增】请求麦克风权限(如果尚未授权)
if audioSession.recordPermission != .granted { // if audioSession.recordPermission != .granted {
audioSession.requestRecordPermission { granted in // audioSession.requestRecordPermission { granted in
if !granted { // if !granted {
print("麦克风权限被拒绝") // print("麦克风权限被拒绝")
} // }
} // }
} // }
// 【新增】激活音频会话(在配置音频引擎之前) // 【新增】激活音频会话(在配置音频引擎之前)
try audioSession.setActive(true) try audioSession.setActive(true)
@ -421,7 +429,7 @@ public class SimpleAudioReceiver: NSObject {
print("当前正在识别") print("当前正在识别")
try audioEngine?.pause() try audioEngine?.pause()
// 先停用以避免冲突 // 先停用以避免冲突
// try audioSession.setActive(false) try audioSession.setActive(false)
} }
print("setAudioOutputRoutecurrent,route=\(route)") print("setAudioOutputRoutecurrent,route=\(route)")

Loading…
Cancel
Save