From 902b44fc0762f42491726281d9172fc44f9b096e Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Tue, 9 Sep 2025 16:47:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=9A=E8=AF=9D=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E9=80=80=E5=87=BA=E5=87=BA=E7=8E=B0=E5=A5=94?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../azure_speech/AzureAsrToAsr.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt index bc154fe05..9a7c42fc4 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt @@ -1090,12 +1090,28 @@ fun getSupportedLanguages(): List { try { Log.d(TAG, "开始清理服务资源") - // 停止连续识别 - if (serviceState.isRecognizing.get()) { - stopContinuousTranslation() + // 停止连续识别(避免调用异步 stopContinuousTranslation 后立刻 reset 导致被取消) + runCatching { serviceState.isRecognizing.set(false) } + try { + recognizer?.stopContinuousRecognitionAsync() + ?.get(1500, java.util.concurrent.TimeUnit.MILLISECONDS) + } catch (t: Throwable) { + Log.w(TAG, "清理阶段停止识别器超时或失败", t) } - // 添加协程清理 + // 停止录音线程(打断并短等待退出) + runCatching { audioProcessor?.stopRecording() } + .onFailure { Log.w(TAG, "清理阶段停止录音失败", it) } + + // 关闭录音文件(若有) + runCatching { recordfile1?.closeFile(true) } + .onFailure { Log.w(TAG, "清理阶段关闭录音文件失败", it) } + + // 清理翻译/合成状态位(不额外等待,避免阻塞主线程) + serviceState.isTranslating.set(false) + serviceState.isSynthesizing.set(false) + + // 添加协程清理(放在资源停止之后,避免取消正在进行的停止协程) resetCoroutineScope() // 清理识别器 From 888839e17de279c78ef3125520d6ee8d17fdd22c Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Tue, 9 Sep 2025 16:51:38 +0800 Subject: [PATCH 2/2] 1 --- lib/modules/settings/views/settings_view.dart | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index a5d7149e8..42b9daa3d 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -514,28 +514,28 @@ class SettingsView extends GetView { // color: isDarkMode // ? Colors.white.withOpacity(0.1) // : Colors.grey[200]), - //BLE测试 - _buildSimpleNavigationSetting( - title: 'opus解码测试', - subtitle: '测试opus解码', - icon: Icons.bluetooth_searching, - iconBgColor: isDarkMode - ? Colors.green[900]!.withOpacity(0.3) - : Colors.green[100]!, - iconColor: - isDarkMode ? Colors.green[300]! : Colors.green[600]!, - titleColor: isDarkMode ? Colors.white : null, - subtitleColor: isDarkMode ? Colors.white70 : null, - onTap: () { - Get.toNamed(Routes.opusTest); - }, - isDarkMode: isDarkMode, - ), - Divider( - height: 1, - color: isDarkMode - ? Colors.white.withOpacity(0.1) - : Colors.grey[200]), + // //BLE测试 + // _buildSimpleNavigationSetting( + // title: 'opus解码测试', + // subtitle: '测试opus解码', + // icon: Icons.bluetooth_searching, + // iconBgColor: isDarkMode + // ? Colors.green[900]!.withOpacity(0.3) + // : Colors.green[100]!, + // iconColor: + // isDarkMode ? Colors.green[300]! : Colors.green[600]!, + // titleColor: isDarkMode ? Colors.white : null, + // subtitleColor: isDarkMode ? Colors.white70 : null, + // onTap: () { + // Get.toNamed(Routes.opusTest); + // }, + // isDarkMode: isDarkMode, + // ), + // Divider( + // height: 1, + // color: isDarkMode + // ? Colors.white.withOpacity(0.1) + // : Colors.grey[200]), // BLE测试 // _buildSimpleNavigationSetting(