diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index 0ed92e073..396d3ecc2 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt @@ -480,13 +480,14 @@ object AgentService : CoroutineScope { "phone_call" -> { // 通话模式:禁用空闲检测,保持持续激活 Log.d(TAG, "通话模式:禁用空闲检测") + startIdleCheck(mode,maxIdleSeconds) return } else -> { // 未知模式:使用默认的空闲检测 Log.w(TAG, "未知识别模式: $mode,使用默认空闲检测") - startIdleCheck(maxIdleSeconds) + startIdleCheck(mode,maxIdleSeconds) } } } @@ -494,7 +495,7 @@ object AgentService : CoroutineScope { /** * 启动空闲检测 */ - private fun startIdleCheck(idleSeconds: Int = maxIdleSeconds) { + private fun startIdleCheck(mode: String,idleSeconds: Int = maxIdleSeconds) { stopIdleCheck() // 先停止现有的检查 if (!isRecognitionActive) return @@ -503,8 +504,8 @@ object AgentService : CoroutineScope { idleCheckJob = launch { try { delay(idleSeconds * 1000L) - - if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming) { + Log.d(TAG, "空闲检测触发自动停止,isActive: $isActive, isRecognitionActive: $isRecognitionActive, isTtsSpeaking: $isTtsSpeaking, isAiStreaming: $isAiStreaming, mode: $mode") + if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming && mode != "phone_call") { Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode") BleService.closeCodec() stopRecognition() @@ -517,6 +518,10 @@ object AgentService : CoroutineScope { ) ) } + if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming && mode == "phone_call") { + Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode") + startRecognition(false, mode) + } } catch (e: CancellationException) { // 协程被取消,正常行为 } catch (e: Exception) { @@ -531,6 +536,7 @@ object AgentService : CoroutineScope { private fun stopIdleCheck() { idleCheckJob?.cancel() idleCheckJob = null + Log.d(TAG, "空闲检测已停止") } /** @@ -643,11 +649,9 @@ object AgentService : CoroutineScope { override fun onRecognizing(sessionid:String, recognizing: String, detectedLanguage: String) { if (recognizing.isNotEmpty()&&isKeepResult==true) { // 检测到语音,更新状态 - - _hasSpeechDetected.set(true) - - Log.d(TAG, "ai识别中重置定时器") - restartIdleCheck() + _hasSpeechDetected.set(true) + Log.d(TAG, "ai识别中重置定时器") + restartIdleCheck() sendEvent( diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt index 76219fcb3..09fc9ebe6 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt @@ -1006,7 +1006,7 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin { val pcmData = extractPcmFromWav(audioData) if (pcmData.isNotEmpty()) { FileLogger.d(tag, "提取PCM数据,大小=${pcmData.size}字节") - BleService.writeExternalRightAudioData(pcmData) + BleService.writeExternalAudioData(pcmData) } else { FileLogger.e(tag, "提取PCM数据失败,音频数据可能不是WAV格式")