Browse Source

优化超时处理

newdev_shunjiawei
liwei1dao 10 months ago
parent
commit
7e48505dc9
  1. 12
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  2. 9
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

12
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -527,10 +527,12 @@ object AgentService : CoroutineScope {
try { try {
delay(idleSeconds * 1000L) delay(idleSeconds * 1000L)
Log.d(TAG, "空闲检测触发自动停止,isActive: $isActive, isRecognitionActive: $isRecognitionActive, isTtsSpeaking: $isTtsSpeaking, isAiStreaming: $isAiStreaming, mode: $mode") Log.d(TAG, "空闲检测触发自动停止,isActive: $isActive, isRecognitionActive: $isRecognitionActive, isTtsSpeaking: $isTtsSpeaking, isAiStreaming: $isAiStreaming, mode: $mode")
if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming && mode != "phone_call") { if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming) {
Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode") Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode")
BleService.closeCodec() BleService.closeCodec()
stopRecognition() if (mode != "phone_call"){
stopRecognition()
}
sendEvent( sendEvent(
"auto_stop", "auto_stop",
mapOf( mapOf(
@ -540,10 +542,6 @@ object AgentService : CoroutineScope {
) )
) )
} }
if (isActive && isRecognitionActive && !isTtsSpeaking && !isAiStreaming && mode == "phone_call") {
Log.d(TAG, "空闲检测触发自动停止,模式: $currentRecognitionMode")
startRecognition(false, mode)
}
} catch (e: CancellationException) { } catch (e: CancellationException) {
// 协程被取消,正常行为 // 协程被取消,正常行为
} catch (e: Exception) { } catch (e: Exception) {

9
local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

@ -407,9 +407,12 @@ class AgentServiceImpl: NSObject {
log: self.logger, log: self.logger,
type: .info, type: .info,
self.currentRecognitionMode) self.currentRecognitionMode)
if self.isRecognizing && !self.isSpeaking && !self.isAiStreaming { //打电话模式下面 不能关闭识别器
if self.isRecognizing && !self.isSpeaking && !self.isAiStreaming{
BleService.shared.closeCodec() BleService.shared.closeCodec()
self.stopRecognition() if (currentRecognitionMode != "phone_call"){
self.stopRecognition()
}
self.sendEvent(name: "auto_stop", data: [ self.sendEvent(name: "auto_stop", data: [
"reason": "idle_timeout", "reason": "idle_timeout",
"seconds": idleSeconds, "seconds": idleSeconds,
@ -493,7 +496,7 @@ class AgentServiceImpl: NSObject {
sendError("启动语音识别失败", code: "RECOGNITION_START_ERROR") sendError("启动语音识别失败", code: "RECOGNITION_START_ERROR")
return false return false
} }
if(useBle){ if(useBle){
isKeepResult = true isKeepResult = true
} }
// 根据模式启动相应的空闲检测(此处 guard isRecognizing,会在 onSessionStarted 中再次启动) // 根据模式启动相应的空闲检测(此处 guard isRecognizing,会在 onSessionStarted 中再次启动)

Loading…
Cancel
Save