fix: fence voice turns and playback; add opt-in face context

This commit is contained in:
zenord
2026-10-11 20:50:11 +08:00
parent 885bb3f2db
commit 9b428fb76f
46 changed files with 2306 additions and 32 deletions
+32
View File
@@ -0,0 +1,32 @@
package com.gorios.lanvoice.net
// Event doubles isolate DialogueClient callback ordering from the unchanged JSON parser.
// Production DialogueProtocol/JSONObject were compiled separately with actual dependencies.
class Payload(private val ok: Boolean = true, private val turn: Long? = null, private val state: String = "", private val reason: String = "") {
fun optBoolean(key: String, fallback: Boolean) = if (key == "ok") ok else fallback
fun optString(key: String, fallback: String = "") = when (key) { "state" -> state; "reason" -> reason; else -> fallback }
fun optInt(key: String, fallback: Int) = if (key == "context_face_cue_version") 1 else fallback
fun opt(key: String): Any? = if (key == "turn_id") turn else null
}
enum class EventKind { AUTH, HELLO, ERROR, HISTORY, UNKNOWN, LISTEN, VAD, STT, LLM, TTS, ABORT }
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 {
val uplinks = mutableListOf<Triple<Long, Long, Int>>()
fun faceCue(turn: Long, observation: com.gorios.lanvoice.expression.FaceCueObservation, age: Long) = "face_cue"
fun hello() = "hello"
fun listen(start: Boolean) = "listen"
fun abort(turn: Long) = "abort"
fun playbackDrained(turn: Long) = "drained"
fun uplink(pcm: ByteArray, turn: Long, seq: Long): ByteArray { uplinks.add(Triple(turn, seq, pcm.size)); return pcm }
fun parseDownlink(bytes: ByteArray) = DownlinkFrame()
fun parseEvent(text: String) = when (text) {
"auth" -> ServerEvent("auth", EventKind.AUTH, Payload())
"auth failed" -> ServerEvent("auth", EventKind.AUTH, Payload(false))
"hello" -> ServerEvent("hello", EventKind.HELLO, Payload())
"error" -> ServerEvent("error", EventKind.ERROR, Payload())
"unknown" -> ServerEvent("auth_ready", EventKind.UNKNOWN, Payload())
"history" -> ServerEvent("history", EventKind.HISTORY, Payload())
else -> error("malformed")
}
}