|
|
|
@ -328,10 +328,14 @@ class IntegratedSpeechTranslationService( |
|
|
|
confidence |
|
|
|
) |
|
|
|
Log.d(TAG, "识别完成事件: ${event.result.text},serviceConfig.sourceLanguage:${serviceConfig.sourceLanguage}") |
|
|
|
// 触发翻译流程 |
|
|
|
launch { |
|
|
|
Log.d(TAG, "触发翻译流程: ${event.result.text}") |
|
|
|
processTranslationAndSynthesis(event.result.text) |
|
|
|
// 只有在服务仍在运行时才触发翻译流程 |
|
|
|
if (serviceState.isRecognizing.get()) { |
|
|
|
launch { |
|
|
|
Log.d(TAG, "触发翻译流程: ${event.result.text}") |
|
|
|
processTranslationAndSynthesis(event.result.text) |
|
|
|
} |
|
|
|
} else { |
|
|
|
Log.d(TAG, "服务已停止,跳过翻译流程: ${event.result.text}") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -478,6 +482,7 @@ class IntegratedSpeechTranslationService( |
|
|
|
recognizer?.stopContinuousRecognitionAsync() |
|
|
|
audioProcessor?.stopRecording() |
|
|
|
recordfile1!!.closeFile(true) |
|
|
|
serviceState.isRecognizing.set(false) |
|
|
|
// 等待当前处理完成 |
|
|
|
while (serviceState.isTranslating.get() || serviceState.isSynthesizing.get()) { |
|
|
|
Thread.sleep(100) |
|
|
|
@ -494,7 +499,13 @@ class IntegratedSpeechTranslationService( |
|
|
|
* 处理翻译和合成流程 |
|
|
|
*/ |
|
|
|
private suspend fun processTranslationAndSynthesis(text: String) { |
|
|
|
Log.d(TAG, " 翻译状态:${serviceState.isTranslating.get()}") |
|
|
|
// 检查服务是否仍在运行 |
|
|
|
if (!serviceState.isRecognizing.get()) { |
|
|
|
Log.d(TAG, "服务已停止,取消翻译流程: $text") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
Log.d(TAG, " 翻译状态:${serviceState.isTranslating.get()}") |
|
|
|
if (serviceState.isTranslating.get()) { |
|
|
|
Log.w(TAG, "翻译正在进行中,跳过当前请求") |
|
|
|
return |
|
|
|
|