Skip to content

Commit

Permalink
Add blocker for ASR #2495
Browse files Browse the repository at this point in the history
  • Loading branch information
sangho.lee committed Jul 1, 2024
1 parent 287ca36 commit 94d0266
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nugu-agent/src/main/java/com/skt/nugu/sdk/agent/DefaultASRAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.skt.nugu.sdk.core.interfaces.context.*
import com.skt.nugu.sdk.core.interfaces.dialog.DialogAttributeStorageInterface
import com.skt.nugu.sdk.core.interfaces.directive.BlockingPolicy
import com.skt.nugu.sdk.core.interfaces.directive.DirectiveHandlerResult
import com.skt.nugu.sdk.core.interfaces.directive.DirectiveProcessorInterface
import com.skt.nugu.sdk.core.interfaces.focus.ChannelObserver
import com.skt.nugu.sdk.core.interfaces.focus.FocusState
import com.skt.nugu.sdk.core.interfaces.focus.SeamlessFocusManagerInterface
Expand All @@ -55,6 +56,7 @@ import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock

class DefaultASRAgent(
private val directiveProcessorInterface: DirectiveProcessorInterface,
private val inputProcessorManager: InputProcessorManagerInterface,
private val focusManager: SeamlessFocusManagerInterface,
private val messageSender: MessageSender,
Expand Down Expand Up @@ -144,6 +146,7 @@ class DefaultASRAgent(
private var focusState = FocusState.NONE

private var waitingFocusInternalStartRecognitionParam: InternalStartRecognitionParam? = null
private var currentDirectiveBlocker: DirectiveProcessorInterface.Blocker? = null
private var currentRequest: Pair<SpeechRecognizer.Request, InternalStartRecognitionParam>? = null

private var expectSpeechDirectiveParam: ExpectSpeechDirectiveParam? = null
Expand Down Expand Up @@ -856,6 +859,10 @@ class DefaultASRAgent(

param.callback?.onError(UUIDGeneration.timeUUID().toString(), ASRAgentInterface.StartRecognitionCallback.ErrorType.ERROR_CANNOT_START_RECOGNIZER)
} else {
DirectiveProcessorInterface.Blocker(it.eventMessage.dialogRequestId, BlockingPolicy.MEDIUM_AUDIO_ONLY).also { blocker->
currentDirectiveBlocker = blocker
directiveProcessorInterface.addDirectiveBlocker(blocker)
}
currentRequest = Pair(it, param)
param.callback?.onSuccess(it.eventMessage.dialogRequestId)
}
Expand Down Expand Up @@ -932,6 +939,10 @@ class DefaultASRAgent(
SpeechRecognizer.State.STOP -> {
currentAudioProvider?.releaseAudioInputStream(this)
currentAudioProvider = null
currentDirectiveBlocker?.let {
directiveProcessorInterface.removeDirectiveBlocker(it)
}
currentDirectiveBlocker = null
currentRequest = null
ASRAgentInterface.State.IDLE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ class NuguAndroidClient private constructor(
}

DefaultASRAgent(
getDirectiveSequencer(),
getInputManagerProcessor(),
getAudioSeamlessFocusManager(),
getMessageSender(),
Expand Down

0 comments on commit 94d0266

Please sign in to comment.