feat: merge reply emotions while preserving configurable Qwen/Doubao provider

This commit is contained in:
zenord
2026-10-12 10:57:14 +08:00
parent 19a7adccd9
commit d43c7d4e80
36 changed files with 1264 additions and 98 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ class AudioCapture {
fun release() {}
}
class AudioPlayback(onDrained: (Long, Long) -> Unit, onError: (Long, Exception) -> Unit, onProgress: (Long, Long, String) -> Unit = { _, _, _ -> }) {
companion object { var interrupts = 0; var enqueued = 0 }
companion object { var interrupts = 0; var enqueued = 0; var lastDrained: ((Long, Long) -> Unit)? = null }
init { lastDrained = onDrained }
fun beginTurn(turn: Long) {}
fun endTurn(turn: Long) {}
fun enqueue(frame: DownlinkFrame): Boolean { enqueued++; return true }
+27
View File
@@ -407,8 +407,35 @@ fun runChecks() {
frameMethod.invoke(session, DownlinkFrame(turnId=3))
check(com.gorios.lanvoice.audio.AudioPlayback.enqueued == beforeFrames + 4)
check(states.last().phase == com.gorios.lanvoice.audio.VoicePhase.ANSWERING)
fun emotion(turn: Long, seq: Long, kind: String = "happy", strength: Int = 2) {
eventMethod.invoke(session, ServerEvent("reply.emotion", EventKind.REPLY_EMOTION,
Payload(turn=turn, fields=mapOf("seq" to seq, "emotion" to kind, "intensity" to strength, "source" to "model"))))
}
emotion(3, 100)
check(states.last().replyEmotion.label == "高兴·明显")
emotion(3, 99, "angry") // out-of-order same-turn event
emotion(2, 101, "angry") // retired turn
emotion(99, 102, "angry") // unannounced turn must not advance current turn
check(states.last().replyEmotion.label == "高兴·明显")
emotion(3, 103, "invalid")
check(states.last().replyEmotion.label == "中立")
emotion(3, 104, "sad", 1)
check(states.last().replyEmotion.label == "难过·轻度")
event(EventKind.TTS, 3, state="stop")
check(states.last().phase == com.gorios.lanvoice.audio.VoicePhase.ANSWERING)
check(states.last().replyEmotion.label == "难过·轻度") // tts.stop does not mean native drain
checkNotNull(com.gorios.lanvoice.audio.AudioPlayback.lastDrained)(3, 0)
Handler.drain()
check(states.last().replyEmotion.label == "中立")
emotion(3, 105) // a late event after drained cannot reanimate the expression
check(states.last().replyEmotion.label == "中立")
event(EventKind.ABORT, 4, reason="new_turn")
emotion(4, 106)
check(states.last().replyEmotion.label == "高兴·明显")
session.interrupt()
check(states.last().replyEmotion.label == "中立")
event(EventKind.ABORT, 4, reason="client_abort")
check(states.last().replyEmotion.label == "中立")
event(EventKind.UNKNOWN, 4)
event(EventKind.ABORT, 4, reason="new_turn")
check(blockedField.get(session) == null)
+3 -3
View File
@@ -2,13 +2,13 @@ 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 = "") {
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 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
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 }
enum class EventKind { AUTH, HELLO, ERROR, HISTORY, UNKNOWN, LISTEN, VAD, STT, LLM, TTS, ABORT, REPLY_EMOTION }
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 {