Browse Source

通话翻译直接退出出现奔溃

newdev_shunjiawei
fdp 1 year ago
parent
commit
902b44fc07
  1. 24
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt

24
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt

@ -1090,12 +1090,28 @@ fun getSupportedLanguages(): List<String> {
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()
// 清理识别器

Loading…
Cancel
Save