Add opt-in face presence departure and return speech

This commit is contained in:
zenord
2026-10-13 16:38:08 +08:00
parent 40abf3a14e
commit d0c1d7eb3d
21 changed files with 913 additions and 89 deletions
+5 -2
View File
@@ -5,10 +5,11 @@ package com.gorios.lanvoice.net
class Payload(private val ok: Boolean = true, private val turn: Long? = null, private val state: String = "", private val reason: String = "", private val fields: Map<String, Any> = emptyMap()) {
fun optBoolean(key: String, fallback: Boolean) = if (key == "ok") ok else fields[key] as? Boolean ?: fallback
fun optString(key: String, fallback: String = "") = when (key) { "state" -> state; "reason" -> reason; else -> fields[key] as? String ?: fallback }
fun optInt(key: String, fallback: Int) = if (key == "context_face_cue_version") 1 else fallback
fun optInt(key: String, fallback: Int) = if (key == "context_face_cue_version") 1 else fields[key] as? Int ?: fallback
fun optJSONObject(key: String): Payload? = fields[key] as? Payload
fun opt(key: String): Any? = if (key == "turn_id") turn else fields[key]
}
enum class EventKind { AUTH, HELLO, ERROR, HISTORY, UNKNOWN, LISTEN, VAD, STT, LLM, TTS, ABORT, REPLY_EMOTION, EXPRESSION_PREPARE, ACTION, CAPABILITIES, SPEECH }
enum class EventKind { AUTH, HELLO, ERROR, HISTORY, UNKNOWN, LISTEN, VAD, STT, LLM, TTS, ABORT, REPLY_EMOTION, EXPRESSION_PREPARE, ACTION, CAPABILITIES, SPEECH, PRESENCE }
data class ServerEvent(val type: String, val kind: EventKind, val payload: Payload)
class DownlinkFrame(val turnId: Long = 0, val sequence: Long = 0, val pcm16: ByteArray = ByteArray(2))
object DialogueProtocol {
@@ -17,6 +18,8 @@ object DialogueProtocol {
fun faceCue(turn: Long, observation: com.gorios.lanvoice.expression.FaceCueObservation, age: Long) = "face_cue"
fun hello(actionPackSha: String? = null,pendingPackSha: String?=null) = "hello"
fun capabilitiesReady(pin: String) = "capabilities_ready"
fun presence(id: Long,turn: Long,kind: com.gorios.lanvoice.expression.PresenceKind,age: Long) = "presence_${kind.wire}/$id/$turn"
fun presenceCancel(id: Long) = "presence_cancel/$id"
fun listen(start: Boolean) = "listen"
fun abort(turn: Long) = "abort"
fun playbackDrained(turn: Long) = "drained"