Browse Source

优化超时处理

weicu
liwei1dao 10 months ago
parent
commit
9098158297
  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 {
delay(idleSeconds * 1000L)
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")
BleService.closeCodec()
stopRecognition()
BleService.closeCodec()
if (mode != "phone_call"){
stopRecognition()
}
sendEvent(
"auto_stop",
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: Exception) {

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

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

Loading…
Cancel
Save