|
|
|
@ -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( |
|
|
|
|