Browse Source

修复面对面翻译

newdev_shunjiawei
fdp 1 year ago
parent
commit
45d08531aa
  1. 527
      lib/modules/translation/controllers/translation_controller.dart
  2. 73
      lib/modules/translation/views/translation_view.dart

527
lib/modules/translation/controllers/translation_controller.dart

File diff suppressed because it is too large

73
lib/modules/translation/views/translation_view.dart

@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:ui';
import 'dart:io';
@ -538,57 +537,6 @@ class TranslationView extends GetView<TranslationController> {
);
}
// // 按住说话按钮组件
// Widget _buildHoldToTalkButton({
// required bool isDarkMode,
// required int speakerId,
// required int activeSpeaker,
// required IconData icon,
// required String label,
// }) {
// bool isActive = activeSpeaker == speakerId;
// return Listener(
// onPointerDown: (_) {
// if (activeSpeaker == 0) {
// // 没有激活的按钮时才能激活
// if (speakerId == 1) {
// //耳机收音
// controller.restoreOriginalAudioState();
// //controller.setActiveSpeaker(speakerId);
// } else {
// controller.disableBluetoothAudio();
// }
// controller.setActiveSpeaker(speakerId);
// //controller.startRecognition();
// }
// },
// onPointerUp: (_) {
// if (isActive) {
// //controller.stopRecognition();
// controller.setActiveSpeaker(0);
// }
// },
// child: Container(
// width: 60.w,
// height: 60.w,
// decoration: BoxDecoration(
// color: isActive
// ? (isDarkMode ? Colors.green[700] : Colors.green) // 激活状态颜色
// : (isDarkMode ? AppColors.primary : Colors.blue),
// shape: BoxShape.circle,
// ),
// child: Icon(
// Icons.mic, // 麦克风图标
// color: isActive ? Colors.white : Colors.white.withOpacity(0.7),
// size: 30.sp,
// ),
// ),
// );
// }
// 按住说话按钮组件
Widget _buildHoldToTalkButton({
required bool isDarkMode,
@ -599,22 +547,25 @@ class TranslationView extends GetView<TranslationController> {
}) {
bool isActive = activeSpeaker == speakerId;
bool isDisabled = activeSpeaker != 0 && activeSpeaker != speakerId;
Timer? _holdTimer; // 增加延迟触发的计时器
return Listener(
onPointerDown: (_) async {
// 同步检查权限状态,不使用 await
// 检查权限
if (!controller.hasRecordPermission.value) {
Get.snackbar('权限提示', '需要麦克风权限才能使用录音功能');
return;
}
controller.setActiveSpeaker(speakerId);
},
onPointerUp: (_) {
controller.setActiveSpeaker(0);
// 只有在没有其他按钮激活时才能激活当前按钮
if (activeSpeaker == 0) {
await controller.setActiveSpeaker(speakerId);
}
},
onPointerCancel: (_) {
controller.setActiveSpeaker(0);
onPointerUp: (_) async {
// 松开按钮时,如果当前按钮是激活状态,则停止
if (isActive) {
await controller.setActiveSpeaker(0);
}
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
@ -643,7 +594,7 @@ class TranslationView extends GetView<TranslationController> {
Stack(
alignment: Alignment.center,
children: [
// 设备类型图标(叠加在麦克风上)
// 设备类型图标
Icon(
icon,
color: isActive

Loading…
Cancel
Save