From 2b70b7dd72580806c337d48f03820c676ac9938c Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 23 Apr 2026 16:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8C=87=E4=BB=A4=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=BF=BB=E8=AF=91=E5=BC=80=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/translation_controller.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/modules/translation/controllers/translation_controller.dart b/lib/modules/translation/controllers/translation_controller.dart index 3ddaf957c..d6c2a6305 100644 --- a/lib/modules/translation/controllers/translation_controller.dart +++ b/lib/modules/translation/controllers/translation_controller.dart @@ -133,6 +133,7 @@ class TranslationController extends GetxController with WidgetsBindingObserver { final appDocDir = getApplicationDocumentsDirectory(); var appDir; var dir; + late Future _initServicesFuture; // ==================== 管理器 ==================== late final RecordTimerController _timerManager; @@ -565,7 +566,7 @@ class TranslationController extends GetxController with WidgetsBindingObserver { loadTranslationHistory(); // 初始化服务 - _initServices(); + _initServicesFuture = _initServices(); // 初始化历史管理器 _historyManager.initialize(); @@ -595,8 +596,8 @@ class TranslationController extends GetxController with WidgetsBindingObserver { if (currentMode.value != 'call') { await changeTranslationMode('call'); } - if (!isRecording.value) { - await startRecording(); + if (!isRecognizing.value) { + await startRecognition(); } } else { await stopAll(); @@ -612,8 +613,10 @@ class TranslationController extends GetxController with WidgetsBindingObserver { Logger.info('[CALL_TRANS_CMD] 检测到 autoStart=true, 进入通话翻译并自启动'); Future.microtask(() async { try { - if (!isRecording.value) { - await startRecording(); + // 等待服务初始化完成(含 AST 端到端服务),再启动完整识别流程 + await _initServicesFuture; + if (!isRecognizing.value) { + await startRecognition(); } } catch (e, s) { Logger.e('TRANSL', '[CALL_TRANS_CMD] autoStart 启动失败: $e', e, s); @@ -1010,6 +1013,8 @@ class TranslationController extends GetxController with WidgetsBindingObserver { /// 开始录音 Future startRecording() async { + // 等待服务初始化完成,确保 dir 已赋值 + await _initServicesFuture; _timerManager.startTimer(); final formattedTime = DateFormat('yyyyMMdd_HHmmss').format(DateTime.now()); AudioSourceType audioSourceType;