Add opt-in face presence departure and return speech
This commit is contained in:
+3
-1
@@ -19,6 +19,7 @@ def avatarUiCandidate = providers.gradleProperty('avatarUiCandidate').orNull ==
|
||||
def avatarMouthCandidate = providers.gradleProperty('avatarMouthCandidate').orNull == 'true'
|
||||
def avatarActionCandidate = providers.gradleProperty('avatarActionCandidate').orNull == 'true'
|
||||
def avatarStartupFix = providers.gradleProperty('avatarStartupFix').orNull == 'true'
|
||||
def presenceCandidate = providers.gradleProperty('presenceCandidate').orNull == 'true'
|
||||
def avatarPlaybackClockFix = providers.gradleProperty('avatarPlaybackClockFix').orNull == 'true'
|
||||
def avatarPlaybackDiagnostic = providers.gradleProperty('avatarPlaybackDiagnostic').orNull == 'true'
|
||||
def avatarRuntimeFix = providers.gradleProperty('avatarRuntimeFix').orNull == 'true'
|
||||
@@ -38,6 +39,7 @@ def emotionManifestSha = providers.gradleProperty('emotionManifestSha').orNull ?
|
||||
if (emotionManifestSha && !(emotionManifestSha ==~ /[0-9a-f]{64}/)) throw new GradleException('Emotion graph requires exact external manifest SHA')
|
||||
if (emotionManifestSha && (!avatarActionCandidate || !avatarMouthCandidate || !avatarNatural || actionVersionCode < 17)) throw new GradleException('Emotion candidate requires own-mouth runtime and a fresh code >=17')
|
||||
if (avatarFullActionCandidate && (!emotionManifestSha || !avatarActionCandidate || actionVersionCode < 18)) throw new GradleException('Full candidate requires pinned emotion/action graph and fresh code >=18')
|
||||
if (presenceCandidate && (!avatarStartupFix || actionVersionCode < 23)) throw new GradleException('Presence candidate requires startup fix and fresh code >=23')
|
||||
if (avatarStartupFix && (!avatarPlaybackClockFix || actionVersionCode < 22)) throw new GradleException('Startup fix requires repaired playback and fresh code >=22')
|
||||
if (avatarPlaybackClockFix && (!avatarFullActionCandidate || actionVersionCode < 21 || emotionManifestSha != '987e125a7d7a2cde99121b5f5246c82f4dbe36c4899d3d49eaffd1a68bafb887')) throw new GradleException('Playback clock fix requires frozen full graph and fresh code >=21')
|
||||
if (avatarPlaybackDiagnostic && (!avatarFullActionCandidate || actionVersionCode < 20 || emotionManifestSha != '987e125a7d7a2cde99121b5f5246c82f4dbe36c4899d3d49eaffd1a68bafb887')) throw new GradleException('Playback diagnostic requires frozen full graph and fresh code >=20')
|
||||
@@ -91,7 +93,7 @@ android {
|
||||
targetSdk 34
|
||||
testInstrumentationRunner 'com.gorios.lanvoice.AvatarCleanUiInstrumentation'
|
||||
versionCode avatarActionCandidate ? actionVersionCode : (avatarMouthCandidate ? 15 : (avatarUiCandidate ? 14 : (avatarNatural ? 13 : 12)))
|
||||
versionName = avatarStartupFix ? '0.7.4' : avatarPlaybackClockFix ? '0.7.3' : avatarPlaybackDiagnostic ? '0.7.2' : avatarRuntimeFix ? '0.7.1' : (avatarActionCandidate ? '0.7.0' : ((avatarUiCandidate || avatarMouthCandidate) ? '0.6.2' : '0.6.1'))
|
||||
versionName = presenceCandidate ? '0.7.5' : avatarStartupFix ? '0.7.4' : avatarPlaybackClockFix ? '0.7.3' : avatarPlaybackDiagnostic ? '0.7.2' : avatarRuntimeFix ? '0.7.1' : (avatarActionCandidate ? '0.7.0' : ((avatarUiCandidate || avatarMouthCandidate) ? '0.6.2' : '0.6.1'))
|
||||
ndk { abiFilters 'arm64-v8a' }
|
||||
}
|
||||
compileOptions { sourceCompatibility JavaVersion.VERSION_17; targetCompatibility JavaVersion.VERSION_17 }
|
||||
|
||||
@@ -43,6 +43,7 @@ class MainActivity : ComponentActivity() {
|
||||
private lateinit var session: VoiceSession
|
||||
private lateinit var audioOutput: AudioOutputGate
|
||||
private var shareFace by mutableStateOf(false)
|
||||
private var presenceEnabled by mutableStateOf(false)
|
||||
private lateinit var entry: AutoConversation
|
||||
private var entryPhase by mutableStateOf(EntryPhase.CONNECTING)
|
||||
private var permissionMessage by mutableStateOf<String?>(null)
|
||||
@@ -194,6 +195,10 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
},
|
||||
presenceEnabled = presenceEnabled,onPresenceEnabled = { enabled ->
|
||||
presenceEnabled=enabled;preferences().edit().putBoolean("presenceEnabled",enabled).apply()
|
||||
if(::session.isInitialized) session.setPresence(enabled,expressionState.status==ExpressionStatus.ACTIVE)
|
||||
},
|
||||
)
|
||||
}
|
||||
if(BuildConfig.AVATAR_STARTUP_FIX) startShell()
|
||||
@@ -232,7 +237,15 @@ class MainActivity : ComponentActivity() {
|
||||
onState = {
|
||||
if (expressionState.status != it.status) DebugLogUpload.log("audio", "camera state=${it.status.name.lowercase()}")
|
||||
expressionState = it
|
||||
}, onFaceCue = session::observeFace)
|
||||
session.setPresence(presenceEnabled,it.status==ExpressionStatus.ACTIVE)
|
||||
}, onFaceCue = session::observeFace,onPresence = { present,at ->
|
||||
val interactive=(getSystemService(POWER_SERVICE) as android.os.PowerManager).isInteractive
|
||||
val unlocked=!(getSystemService(KEYGUARD_SERVICE) as android.app.KeyguardManager).isKeyguardLocked
|
||||
session.setPresence(presenceEnabled,inForeground && interactive && unlocked && expressionState.status==ExpressionStatus.ACTIVE)
|
||||
session.observePresence(present,at)
|
||||
})
|
||||
presenceEnabled=preferences().getBoolean("presenceEnabled",false)
|
||||
session.setPresence(presenceEnabled,false)
|
||||
if(inForeground) session.foreground(connectAutomatically=false)
|
||||
if(mediaReady) avatarPack?.emotionAction?.actionPack?.let(session::installReviewedActions)
|
||||
scheduleEntry()
|
||||
@@ -324,6 +337,7 @@ class MainActivity : ComponentActivity() {
|
||||
private fun closeCamera() {
|
||||
if(!::expressions.isInitialized) return
|
||||
expressions.stop()
|
||||
session.setPresence(presenceEnabled,false)
|
||||
shareFace = false
|
||||
session.setFaceSharing(false)
|
||||
}
|
||||
|
||||
@@ -74,6 +74,16 @@ class VoiceSession(
|
||||
private var faceCue = FaceCueObservation()
|
||||
private var faceSent = false
|
||||
private val faceDiagnostics = FaceTransmissionDiagnostics()
|
||||
private val presenceRules=com.gorios.lanvoice.expression.PresenceRules()
|
||||
private var presenceEnabled=false
|
||||
private var presenceCamera=false
|
||||
private var presenceSupported=false
|
||||
private var presenceSpeech=false
|
||||
private var lastSpeechAt=0L
|
||||
private data class PresenceRequest(val id: Long,val kind: com.gorios.lanvoice.expression.PresenceKind,
|
||||
var turn: Long?=null,var accepted: Boolean=false)
|
||||
private var presenceRequest: PresenceRequest?=null
|
||||
private var presenceTimeout: Runnable?=null
|
||||
private val faceTick = object : Runnable {
|
||||
override fun run() {
|
||||
if (!faceSharing || released) return
|
||||
@@ -107,6 +117,7 @@ class VoiceSession(
|
||||
diagnostic("playback drained turn=$turn")
|
||||
if (dialogue.playbackDrained(turn)) {
|
||||
drainedTurn=turn
|
||||
if(presenceRequest?.turn==turn) clearPresenceRequest()
|
||||
resetReply("drained")
|
||||
emotionEndedTurn = turn
|
||||
update(state.copy(phase = VoicePhase.LISTENING, replyEmotion = ReplyEmotion()))
|
||||
@@ -237,6 +248,7 @@ class VoiceSession(
|
||||
|
||||
fun stopVoice(sendControls: Boolean = true,cancelReason: String = "stop_voice") {
|
||||
checkMainThread()
|
||||
cancelPresence(reset=true)
|
||||
cancelActionFor(cancelReason)
|
||||
resetReply("stop")
|
||||
val wasActive = state.voiceActive
|
||||
@@ -275,7 +287,7 @@ class VoiceSession(
|
||||
checkMainThread()
|
||||
if (!isActive() || state.microphoneMuted == muted) return
|
||||
update(state.copy(microphoneMuted = muted))
|
||||
if (muted) stopCapture()
|
||||
if (muted) { cancelPresence(reset=true);stopCapture() }
|
||||
else if (state.phase == VoicePhase.LISTENING) startCapture()
|
||||
}
|
||||
|
||||
@@ -326,6 +338,44 @@ class VoiceSession(
|
||||
faceCue = observation
|
||||
}
|
||||
|
||||
fun setPresence(enabled: Boolean,cameraActive: Boolean) {
|
||||
checkMainThread()
|
||||
presenceEnabled=enabled;presenceCamera=cameraActive
|
||||
if(!enabled || !cameraActive) cancelPresence(reset=true)
|
||||
}
|
||||
private fun presenceEligible()=presenceEnabled && presenceCamera && presenceSupported && isActive() && !state.microphoneMuted
|
||||
fun observePresence(present: Boolean?,observedAt: Long) {
|
||||
checkMainThread()
|
||||
if(!presenceEligible()) { presenceRules.reset();return }
|
||||
val now=SystemClock.elapsedRealtime()
|
||||
if(now-observedAt !in 0..350) { presenceRules.sample(null,now,currentTurn,false);return }
|
||||
val idle=state.phase==VoicePhase.LISTENING && !actions.active && presenceRequest==null &&
|
||||
!presenceSpeech && now-lastSpeechAt>=800 && capturing
|
||||
val trigger=presenceRules.sample(present,observedAt,currentTurn,idle,
|
||||
presenceRequest?.kind==com.gorios.lanvoice.expression.PresenceKind.ABSENT,appearedAllowed.get()) ?: return
|
||||
val id=presenceSerial.incrementAndGet()
|
||||
if(id !in 1..UINT32_MASK) return
|
||||
presenceRequest=PresenceRequest(id,trigger.kind)
|
||||
diagnostic("presence state=sent kind=${trigger.kind.wire} request=$id turn=$currentTurn")
|
||||
if(!dialogue.presence(id,trigger.turn,trigger.kind,now-observedAt)) { clearPresenceRequest();return }
|
||||
presenceTimeout=Runnable { cancelPresence(reset=false) }.also { main.postDelayed(it,5_000) }
|
||||
}
|
||||
private fun clearPresenceRequest() {
|
||||
presenceTimeout?.let { main.removeCallbacks(it) };presenceTimeout=null;presenceRequest=null
|
||||
}
|
||||
private fun cancelPresence(reset: Boolean) {
|
||||
val request=presenceRequest
|
||||
clearPresenceRequest()
|
||||
if(reset) presenceRules.reset() else presenceRules.discardPending()
|
||||
if(request!=null && state.connection==ConnectionStatus.CONNECTED) {
|
||||
dialogue.presenceCancel(request.id)
|
||||
if(request.turn==currentTurn) {
|
||||
blockedTurn=currentTurn;playback.interrupt();onPrepareExpression(null);resetReply("presence_cancelled")
|
||||
}
|
||||
diagnostic("presence state=cancelled request=${request.id}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearFaceContext(clearObservation: Boolean = true) {
|
||||
if (faceSent && faceSupported && state.connection == ConnectionStatus.CONNECTED && hasTurn) {
|
||||
val sent = dialogue.sendFaceCue(currentTurn, FaceCueObservation(), 0)
|
||||
@@ -335,7 +385,7 @@ class VoiceSession(
|
||||
if (clearObservation) faceCue = FaceCueObservation()
|
||||
}
|
||||
|
||||
val runtimeProtocolState: String get() = "hello=${dialogue.actionNegotiation} connection=${state.connection.name.lowercase()} turn=$currentTurn drained=$drainedTurn action=${actions.active} capture=$capturing capture_epoch=$captureEpoch"
|
||||
val runtimeProtocolState: String get() = "hello=${dialogue.actionNegotiation} connection=${state.connection.name.lowercase()} turn=$currentTurn drained=$drainedTurn action=${actions.active} capture=$capturing capture_epoch=$captureEpoch presence=$presenceEnabled/$presenceCamera/$presenceSupported/${presenceRequest?.kind?.wire ?: "none"}"
|
||||
fun faceDiagnosticsSnapshot() = faceDiagnostics.snapshot()
|
||||
|
||||
private fun sendFaceContext() {
|
||||
@@ -368,6 +418,7 @@ class VoiceSession(
|
||||
private fun onConnection(connection: ConnectionStatus, reason: String) {
|
||||
diagnostic("connection ${state.connection.name} -> ${connection.name} reason=$reason", "connect")
|
||||
if (connection != ConnectionStatus.CONNECTED) {
|
||||
clearPresenceRequest();presenceRules.reset();presenceSupported=false;presenceSpeech=false
|
||||
cancelActionFor("disconnect")
|
||||
onPrepareExpression(null)
|
||||
resetReply("disconnect")
|
||||
@@ -438,6 +489,29 @@ class VoiceSession(
|
||||
private fun onEvent(event: ServerEvent) {
|
||||
val turn = (event.payload.opt("turn_id") as? Number)?.toLong()
|
||||
diagnostic("onEvent kind=${event.kind.name} turn_id=$turn")
|
||||
if(event.kind==EventKind.PRESENCE) {
|
||||
val request=presenceRequest ?: return
|
||||
if((event.payload.opt("request_id") as? Number)?.toLong()!=request.id) return
|
||||
val accepted=event.payload.optString("state")=="accepted"
|
||||
if(accepted && request.turn==turn && presenceEligible()) {
|
||||
presenceTimeout?.let { main.removeCallbacks(it) };presenceTimeout=null
|
||||
if(!request.accepted && request.kind==com.gorios.lanvoice.expression.PresenceKind.APPEARED)
|
||||
appearedAllowed.set(SystemClock.elapsedRealtime()+600_000)
|
||||
request.accepted=true
|
||||
} else if(!accepted) clearPresenceRequest()
|
||||
else cancelPresence(reset=false)
|
||||
diagnostic("presence state=${if(accepted) "accepted" else "rejected_or_cancelled"} request=${request.id}")
|
||||
return
|
||||
}
|
||||
if(event.kind==EventKind.ABORT && event.payload.optString("reason")=="presence_greeting") {
|
||||
val id=(event.payload.opt("request_id") as? Number)?.toLong()
|
||||
if(id==null || id!=presenceRequest?.id || !presenceEligible()) {
|
||||
if(turn!=null) retiredTurns.add(turn)
|
||||
if(id!=null && id in 1..UINT32_MASK) dialogue.presenceCancel(id)
|
||||
return
|
||||
}
|
||||
presenceRequest?.turn=turn
|
||||
}
|
||||
if (event.kind == EventKind.EXPRESSION_PREPARE) {
|
||||
if (isActive() && hasTurn && turn == currentTurn && blockedTurn != turn && !actions.active) {
|
||||
if (event.type.endsWith(".cancel")) { diagnostic("emotion_prepare state=cancelled turn=$turn");onPrepareExpression(null) }
|
||||
@@ -482,7 +556,10 @@ class VoiceSession(
|
||||
if (turn != null && !acceptTurn(turn)) return
|
||||
val action = event.payload.optString("state", "").ifBlank { event.type.substringAfter('.', "") }
|
||||
when (event.kind) {
|
||||
EventKind.HELLO -> faceSupported = event.payload.optInt("context_face_cue_version", 0) == 1
|
||||
EventKind.HELLO -> {
|
||||
faceSupported = event.payload.optInt("context_face_cue_version", 0) == 1
|
||||
presenceSupported=event.payload.optInt("presence_greeting_version",0)==1
|
||||
}
|
||||
EventKind.LISTEN -> {
|
||||
val active = isActive()
|
||||
diagnostic("LISTEN action=${if (action in setOf("start", "stop")) action else "other"} active=$active blockedTurn=$blockedTurn")
|
||||
@@ -503,6 +580,9 @@ class VoiceSession(
|
||||
}
|
||||
}
|
||||
EventKind.VAD -> if (isActive()) {
|
||||
val kind=event.payload.optJSONObject("event")?.optString("type") ?: ""
|
||||
if(kind=="speech.start") { presenceSpeech=true;lastSpeechAt=SystemClock.elapsedRealtime();cancelPresence(reset=false) }
|
||||
if(kind=="speech.end") { presenceSpeech=false;lastSpeechAt=SystemClock.elapsedRealtime() }
|
||||
update(state.copy(phase = if (action in setOf("end", "stop", "speech_end"))
|
||||
VoicePhase.RECOGNIZING else VoicePhase.LISTENING))
|
||||
}
|
||||
@@ -529,8 +609,9 @@ class VoiceSession(
|
||||
// listen_start aborts the previous reply while announcing the NEW turn.
|
||||
// The server's following LISTEN start and TTS belong to that new turn.
|
||||
val reason = event.payload.optString("reason")
|
||||
if(reason=="voice_barge_in") presenceSpeech=true
|
||||
val listenReset = reason == "listen_start"
|
||||
val announcesNewTurn = reason in setOf("listen_start", "new_turn", "voice_barge_in", "client_abort", "action_followup", "action_cancelled", "action_timeout")
|
||||
val announcesNewTurn = reason in setOf("listen_start", "new_turn", "voice_barge_in", "client_abort", "action_followup", "action_cancelled", "action_timeout", "presence_greeting", "presence_cancelled")
|
||||
blockedTurn = if (announcesNewTurn) null else oldTurn
|
||||
diagnostic("ABORT blockedTurn=$blockedTurn active=${isActive()} listenReset=$listenReset oldTurn=$oldTurn currentTurn=$currentTurn")
|
||||
playback.interrupt()
|
||||
@@ -572,6 +653,8 @@ class VoiceSession(
|
||||
}
|
||||
// IDs identify turns; do not assume the server allocates them in numeric order.
|
||||
if (!hasTurn || id != currentTurn) {
|
||||
presenceRules.discardPending();presenceSpeech=false;lastSpeechAt=SystemClock.elapsedRealtime()
|
||||
if(presenceRequest!=null && presenceRequest?.turn!=id) cancelPresence(reset=false)
|
||||
cancelActionFor("new_turn")
|
||||
onPrepareExpression(null)
|
||||
resetReply("new_turn")
|
||||
@@ -652,6 +735,8 @@ class VoiceSession(
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val presenceSerial=java.util.concurrent.atomic.AtomicLong()
|
||||
private val appearedAllowed=java.util.concurrent.atomic.AtomicLong()
|
||||
private const val BACKGROUND_DISCONNECT_GUIDANCE = "App 退到后台,连接已断开"
|
||||
private const val TAG = "LanVoice"
|
||||
private const val UINT32_MASK = 0xffff_ffffL
|
||||
|
||||
@@ -96,6 +96,7 @@ fun CallScreen(state: VoiceUiState,entry: EntryPhase,permissionMessage: String?,
|
||||
onOfflinePreview: ()->Unit=NoUiAction,
|
||||
startupBase: ContinuousAvatarPack?=null,startupStage: String="ready",
|
||||
onStartupVisible: ()->Unit=NoUiAction,onRetryAssets: ()->Unit=NoUiAction,onStartupFailed: ()->Unit=NoUiAction,
|
||||
presenceEnabled: Boolean=false,onPresenceEnabled: (Boolean)->Unit={},
|
||||
) {
|
||||
val avatar=remember { AvatarController() }.select(state.voiceActive,state.replyEmotion,state.playbackActivity.takeUnless { state.actionActive })
|
||||
val latestAvatar by rememberUpdatedState(avatar)
|
||||
@@ -125,6 +126,11 @@ fun CallScreen(state: VoiceUiState,entry: EntryPhase,permissionMessage: String?,
|
||||
}
|
||||
}
|
||||
Text(status,style=MaterialTheme.typography.titleMedium)
|
||||
Row(verticalAlignment=Alignment.CenterVertically) {
|
||||
Text("人脸出现/离开时主动说话",fontSize=13.sp,modifier=Modifier.weight(1f))
|
||||
Switch(checked=presenceEnabled,onCheckedChange=onPresenceEnabled)
|
||||
}
|
||||
Text("需开启相机;仅发送有人出现/离开事件,不上传照片",fontSize=12.sp)
|
||||
if(startupStage=="failed") {
|
||||
Text("角色准备未完成,基础角色仍可使用",fontSize=12.sp)
|
||||
TextButton(onClick=onRetryAssets) { Text("重试准备角色") }
|
||||
|
||||
@@ -29,6 +29,7 @@ class ExpressionController(
|
||||
private val lifecycleOwner: LifecycleOwner,
|
||||
private val onState: (ExpressionUiState) -> Unit,
|
||||
private val onFaceCue: (FaceCueObservation) -> Unit = {},
|
||||
private val onPresence: (Boolean?,Long) -> Unit = { _,_-> },
|
||||
) {
|
||||
private class Run {
|
||||
@Volatile var active = true
|
||||
@@ -181,6 +182,7 @@ class ExpressionController(
|
||||
mpImage.close()
|
||||
} ?: kotlin.run {
|
||||
run.diagnostics.failed(CameraFailure.NO_RESULT)
|
||||
main.post { if(isCurrent(run)) onPresence(null,now) }
|
||||
return
|
||||
}
|
||||
if (!run.active) return
|
||||
@@ -204,6 +206,7 @@ class ExpressionController(
|
||||
main.post { if (isCurrent(run)) onFaceCue(faceCue) }
|
||||
// UI receives only <=2 enum labels; 52 coefficients, pose and images stay transient.
|
||||
val presence = if (result.faceLandmarks().isEmpty()) FacePresence.ABSENT else FacePresence.PRESENT
|
||||
main.post { if(isCurrent(run)) onPresence(presence==FacePresence.PRESENT,now) }
|
||||
if (run.lastPublished != visible || run.lastStableCue != faceCue.cue || run.lastPresence != presence) {
|
||||
run.lastPresence = presence
|
||||
run.lastStableCue = faceCue.cue
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.gorios.lanvoice.expression
|
||||
|
||||
enum class PresenceKind(val wire: String) { ABSENT("absent"), APPEARED("appeared") }
|
||||
data class PresenceTrigger(val kind: PresenceKind,val turn: Long,val ageMs: Long)
|
||||
|
||||
/** Local booleans only; called on main with monotonic successful sample times. */
|
||||
class PresenceRules(private val absentMs: Long=20_000,private val confirmMs: Long=1_000) {
|
||||
init { require(absentMs in 5_000..600_000 && confirmMs==1_000L) }
|
||||
private var last: Long?=null
|
||||
private var absentSince: Long?=null
|
||||
private var presentSince: Long?=null
|
||||
private var absentAttempted=false
|
||||
private var returnArmed=false
|
||||
private data class Pending(val kind: PresenceKind,val turn: Long,val until: Long)
|
||||
private var pending: Pending?=null
|
||||
fun discardPending() { pending=null }
|
||||
fun reset() { breakContinuity();absentAttempted=false }
|
||||
private fun breakContinuity() { last=null;absentSince=null;presentSince=null;returnArmed=false;pending=null }
|
||||
fun sample(present: Boolean?,now: Long,turn: Long,idle: Boolean,
|
||||
absentInFlight: Boolean=false,appearedAllowedAt: Long=0): PresenceTrigger? {
|
||||
val old=last
|
||||
if(present==null || old!=null && now<=old) { breakContinuity();return null }
|
||||
if(old!=null && now-old>350) breakContinuity()
|
||||
last=now
|
||||
if(!present) {
|
||||
presentSince=null
|
||||
if(pending?.kind==PresenceKind.APPEARED) pending=null
|
||||
val since=absentSince ?: now.also { absentSince=it }
|
||||
if(now-since>=absentMs) {
|
||||
returnArmed=true
|
||||
if(!absentAttempted) {
|
||||
absentAttempted=true
|
||||
if(pending==null) pending=Pending(PresenceKind.ABSENT,turn,now+5_000)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
absentSince=null
|
||||
if(pending?.kind==PresenceKind.ABSENT) pending=null
|
||||
val since=presentSince ?: now.also { presentSince=it }
|
||||
if(now-since>=confirmMs) {
|
||||
absentAttempted=false
|
||||
if(returnArmed) {
|
||||
returnArmed=false
|
||||
// Returning during own departure speech must not queue a second speech.
|
||||
if(!absentInFlight && now>=appearedAllowedAt && pending==null)
|
||||
pending=Pending(PresenceKind.APPEARED,turn,now+5_000)
|
||||
}
|
||||
}
|
||||
}
|
||||
val candidate=pending ?: return null
|
||||
if(now>=candidate.until || candidate.turn!=turn) { pending=null;return null }
|
||||
if(!idle) return null
|
||||
pending=null
|
||||
return PresenceTrigger(candidate.kind,turn,0)
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,9 @@ class DialogueClient(
|
||||
readyUpdateSent=send(DialogueProtocol.capabilitiesReady(pin))
|
||||
return readyUpdateSent
|
||||
}
|
||||
fun presence(id: Long,turn: Long,kind: com.gorios.lanvoice.expression.PresenceKind,age: Long)=
|
||||
send(DialogueProtocol.presence(id,turn,kind,age))
|
||||
fun presenceCancel(id: Long)=send(DialogueProtocol.presenceCancel(id))
|
||||
|
||||
fun connect() {
|
||||
checkMainThread()
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.gorios.lanvoice.expression.FaceCueObservation
|
||||
data class ServerEvent(val type: String, val kind: EventKind, val payload: JSONObject)
|
||||
|
||||
enum class EventKind {
|
||||
AUTH, HELLO, CAPABILITIES, HISTORY, LISTEN, VAD, STT, LLM, TTS, REPLY_EMOTION, EXPRESSION_PREPARE, ACTION, SPEECH, ERROR, ABORT, METRICS, PING, PONG, UNKNOWN
|
||||
AUTH, HELLO, CAPABILITIES, PRESENCE, HISTORY, LISTEN, VAD, STT, LLM, TTS, REPLY_EMOTION, EXPRESSION_PREPARE, ACTION, SPEECH, ERROR, ABORT, METRICS, PING, PONG, UNKNOWN
|
||||
}
|
||||
|
||||
/** Header integers are unsigned, network byte order; PCM samples are signed little endian. */
|
||||
@@ -32,6 +32,7 @@ object DialogueProtocol {
|
||||
.put("sample_rate", 16_000)
|
||||
.put("frame_duration", 20)
|
||||
.put("persona", "default")
|
||||
.put("presence_greeting_version",1)
|
||||
.put("voice_mode", "continuous_voice")
|
||||
.apply { if (actionPackSha?.matches(Regex("[0-9a-f]{64}")) == true) {
|
||||
put("action_protocol", 1); put("action_pack_sha256", actionPackSha)
|
||||
@@ -64,6 +65,16 @@ object DialogueProtocol {
|
||||
fun playbackDrained(turnId: Long): String = JSONObject()
|
||||
.put("type", "playback.drained").put("turn_id", turnId).toString()
|
||||
|
||||
fun presence(id: Long,turn: Long,kind: com.gorios.lanvoice.expression.PresenceKind,age: Long): String {
|
||||
require(id in 1..0xffff_ffffL && turn in 0..0xffff_ffffL && age in 0..1500)
|
||||
return JSONObject().put("type","presence."+kind.wire).put("version",1).put("request_id",id)
|
||||
.put("turn_id",turn).put("present",kind==com.gorios.lanvoice.expression.PresenceKind.APPEARED).put("age_ms",age).toString()
|
||||
}
|
||||
fun presenceCancel(id: Long): String {
|
||||
require(id in 1..0xffff_ffffL)
|
||||
return JSONObject().put("type","presence.cancel").put("version",1).put("request_id",id).toString()
|
||||
}
|
||||
|
||||
fun actionStatus(value: com.gorios.lanvoice.avatar.ActionStatus): String = JSONObject()
|
||||
.put("type", "action.status").put("turn_id", value.turn).put("action_id", value.id)
|
||||
.put("status", value.status).put("asset_id", value.asset ?: "")
|
||||
@@ -108,6 +119,7 @@ object DialogueProtocol {
|
||||
"tts" -> EventKind.TTS
|
||||
"action" -> EventKind.ACTION
|
||||
"speech" -> EventKind.SPEECH
|
||||
"presence" -> EventKind.PRESENCE
|
||||
"error" -> EventKind.ERROR
|
||||
"abort" -> EventKind.ABORT
|
||||
"metrics" -> EventKind.METRICS
|
||||
|
||||
Reference in New Issue
Block a user