|
|
@ -37,10 +37,13 @@ class TranslationController extends GetxController { |
|
|
final bleManager = Get.find<BleManager>(); |
|
|
final bleManager = Get.find<BleManager>(); |
|
|
// 音频输入源 |
|
|
// 音频输入源 |
|
|
bool _audioSourceType = false; |
|
|
bool _audioSourceType = false; |
|
|
// 倒计时器 |
|
|
//是否开启播放 |
|
|
bool istts = false; |
|
|
bool isPlayback = false; |
|
|
|
|
|
//录音计时器 |
|
|
final RxString recordDurationText = '00:00'.obs; |
|
|
final RxString recordDurationText = '00:00'.obs; |
|
|
|
|
|
//记录计时器 |
|
|
Timer? _recordTimer; |
|
|
Timer? _recordTimer; |
|
|
|
|
|
//秒 |
|
|
int _seconds = 0; |
|
|
int _seconds = 0; |
|
|
// 存储相关 |
|
|
// 存储相关 |
|
|
static const String _historyKey = 'translation_history'; |
|
|
static const String _historyKey = 'translation_history'; |
|
|
@ -99,23 +102,24 @@ class TranslationController extends GetxController { |
|
|
activeSpeaker.value = id; |
|
|
activeSpeaker.value = id; |
|
|
// 监听识别结果 |
|
|
// 监听识别结果 |
|
|
if (activeSpeaker.value != 0) { |
|
|
if (activeSpeaker.value != 0) { |
|
|
istts = false; |
|
|
isPlayback = false; |
|
|
_asrService.setcontinue(); |
|
|
_asrService.setContinue(); |
|
|
lastActiveSpeaker.value = id; |
|
|
lastActiveSpeaker.value = id; |
|
|
} else { |
|
|
} else { |
|
|
_asrService.setPause(); |
|
|
_asrService.setPause(); |
|
|
if (fTFTranslationResult != '' && !istts) { |
|
|
if (fTFTranslationResult != '' && !isPlayback) { |
|
|
istts = true; |
|
|
isPlayback = true; |
|
|
await _ttsService.setAudioOutputDevice(lastActiveSpeaker.value); |
|
|
await _ttsService.setAudioOutputDevice(lastActiveSpeaker.value); |
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1300)); |
|
|
await playTranslatedText(fTFTranslationResult!); |
|
|
await playTranslatedText(fTFTranslationResult!); |
|
|
fTFTranslationResult = ''; |
|
|
fTFTranslationResult = ''; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 切换TTS功能 |
|
|
// 禁用蓝牙音频 |
|
|
void disableBluetoothAudio() => _asrService.disableBluetoothAudio(); |
|
|
void disableBluetoothAudio() => _asrService.disableBluetoothAudio(); |
|
|
// 切换TTS功能 |
|
|
//恢复原始音频状态 |
|
|
void restoreOriginalAudioState() => _asrService.restoreOriginalAudioState(); |
|
|
void restoreOriginalAudioState() => _asrService.restoreOriginalAudioState(); |
|
|
|
|
|
|
|
|
// 兼容旧版视图的计算属性 |
|
|
// 兼容旧版视图的计算属性 |
|
|
@ -379,7 +383,8 @@ class TranslationController extends GetxController { |
|
|
if (currentMode.value == 'faceToFace') { |
|
|
if (currentMode.value == 'faceToFace') { |
|
|
_asrService.setPause(); |
|
|
_asrService.setPause(); |
|
|
} else { |
|
|
} else { |
|
|
_asrService.setcontinue(); |
|
|
await _ttsService.setAudioOutputDevice(0); |
|
|
|
|
|
_asrService.setContinue(); |
|
|
} |
|
|
} |
|
|
isRecognizing.value = true; |
|
|
isRecognizing.value = true; |
|
|
if (isRecording.value && isRecognizing.value) { |
|
|
if (isRecording.value && isRecognizing.value) { |
|
|
@ -577,19 +582,20 @@ class TranslationController extends GetxController { |
|
|
fTFTranslationResult = |
|
|
fTFTranslationResult = |
|
|
(fTFTranslationResult ?? '') + translationResult; |
|
|
(fTFTranslationResult ?? '') + translationResult; |
|
|
|
|
|
|
|
|
if (activeSpeaker.value == 0 && !istts) { |
|
|
if (activeSpeaker.value == 0 && |
|
|
istts = true; |
|
|
!isPlayback && |
|
|
|
|
|
currentMode.value == 'faceToFace') { |
|
|
|
|
|
isPlayback = true; |
|
|
await _ttsService.setAudioOutputDevice(lastActiveSpeaker.value); |
|
|
await _ttsService.setAudioOutputDevice(lastActiveSpeaker.value); |
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1300)); |
|
|
await playTranslatedText(fTFTranslationResult!); |
|
|
await playTranslatedText(fTFTranslationResult!); |
|
|
fTFTranslationResult = ''; |
|
|
fTFTranslationResult = ''; |
|
|
; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// 播放TTS - 只在最终结果时播放 |
|
|
// 播放TTS - 只在最终结果时播放 |
|
|
if (isTtsEnabled.value && |
|
|
if (isTtsEnabled.value && |
|
|
isFinal && |
|
|
isFinal && |
|
|
currentMode.value != 'faceToFace') { |
|
|
currentMode.value != 'faceToFace') { |
|
|
_ttsService.setAudioOutputDevice(activeSpeaker.value); |
|
|
|
|
|
await playTranslatedText(translationResult); |
|
|
await playTranslatedText(translationResult); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
|