feat: add single-call action protocol and Android stage interfaces
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import android.os.Handler
|
||||
import com.gorios.lanvoice.audio.*
|
||||
import com.gorios.lanvoice.avatar.*
|
||||
import com.gorios.lanvoice.net.*
|
||||
|
||||
fun checkActionSession() {
|
||||
val sha="a".repeat(64);val states=mutableListOf<VoiceUiState>()
|
||||
val prepared=mutableListOf<com.gorios.lanvoice.dialogue.ReplyEmotion?>()
|
||||
var plays=0;var stopped=0;var ended: ((ActionEnd)->Unit)?=null
|
||||
val player=object: ActionPlayer {
|
||||
override fun play(asset: ActionAsset,finished: (ActionEnd)->Unit,failed: ()->Unit) { plays++;ended=finished }
|
||||
override fun stop(released: ()->Unit) { stopped++;released() }
|
||||
}
|
||||
val session=VoiceSession("localhost",5011,states::add,
|
||||
reviewedActionPack=ReviewedActionPack(sha,listOf(ActionAsset("asset_01",1000),ActionAsset("asset_02",1000))),
|
||||
actionPlayer=player,onPrepareExpression=prepared::add)
|
||||
fun set(name: String,value: Any) { session.javaClass.getDeclaredField(name).apply { isAccessible=true }.set(session,value) }
|
||||
val dialogue=session.javaClass.getDeclaredField("dialogue").apply { isAccessible=true }.get(session) as DialogueClient
|
||||
val socket=FakeSocket();dialogue.setField("socket",socket);dialogue.setField("ready",true)
|
||||
set("foreground",true);set("state",VoiceUiState(connection=ConnectionStatus.CONNECTED))
|
||||
val onEvent=session.javaClass.getDeclaredMethod("onEvent",ServerEvent::class.java).apply { isAccessible=true }
|
||||
fun event(type: String,kind: EventKind,turn: Long,fields: Map<String,Any> = emptyMap()) {
|
||||
onEvent.invoke(session,ServerEvent(type,kind,Payload(turn=turn,fields=fields)))
|
||||
}
|
||||
session.startVoice();event("listen",EventKind.LISTEN,7,mapOf("state" to "start"))
|
||||
event("reply.emotion.prepare",EventKind.EXPRESSION_PREPARE,7,mapOf("seq" to 1L,"emotion" to "happy","intensity" to 1))
|
||||
check(prepared.last()?.emotion==com.gorios.lanvoice.dialogue.RoleEmotion.HAPPY)
|
||||
check(states.last().replyEmotion.turnId==null) // Preload never becomes displayed emotion.
|
||||
event("reply.emotion.prepare",EventKind.EXPRESSION_PREPARE,6,mapOf("seq" to 2L,"emotion" to "sad","intensity" to 1))
|
||||
check(prepared.last()?.emotion==com.gorios.lanvoice.dialogue.RoleEmotion.HAPPY)
|
||||
AudioCapture.confirmStopsAutomatically=false
|
||||
val oldFrame=checkNotNull(AudioCapture.lastFrame)
|
||||
event("action.plan",EventKind.ACTION,7,mapOf("action_id" to "x".repeat(24),"pack_sha256" to sha,"ttl_ms" to 10000L))
|
||||
check(states.last().actionActive && plays==0)
|
||||
val before=DialogueProtocol.uplinks.size
|
||||
oldFrame(ByteArray(640));Handler.drain();check(DialogueProtocol.uplinks.size==before)
|
||||
checkNotNull(AudioCapture.lastStopped)(true);Handler.drain();check(plays==1)
|
||||
val starts=AudioCapture.starts
|
||||
session.setMicrophoneMuted(true);session.setMicrophoneMuted(false);session.interrupt()
|
||||
check(AudioCapture.starts==starts)
|
||||
val enqueued=AudioPlayback.enqueued
|
||||
session.javaClass.getDeclaredMethod("onFrame",DownlinkFrame::class.java).apply { isAccessible=true }.invoke(session,DownlinkFrame(7))
|
||||
check(enqueued==AudioPlayback.enqueued)
|
||||
val stale=checkNotNull(ended)
|
||||
session.background();Handler.drain()
|
||||
check(stopped==1 && !states.last().actionActive && !states.last().voiceActive)
|
||||
stale(ActionEnd(true,true,true));Handler.drain();check(plays==1)
|
||||
session.release();AudioCapture.confirmStopsAutomatically=true
|
||||
println("PASS: actual VoiceSession action plan→capture cleanup fence→player, queued mic/downlink dropped, prepare-only/old-turn, no voice barge, background cancel; doubles only")
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import com.gorios.lanvoice.net.DownlinkFrame
|
||||
enum class AecAvailability { AVAILABLE, UNAVAILABLE, UNKNOWN }
|
||||
// No audio devices in callback propagation tests.
|
||||
class AudioCapture {
|
||||
companion object { var lastFrame: ((ByteArray) -> Unit)? = null; var lastError: ((Exception) -> Unit)? = null; var starts = 0 }
|
||||
companion object { var lastFrame: ((ByteArray) -> Unit)? = null; var lastError: ((Exception) -> Unit)? = null; var starts = 0
|
||||
var confirmStopsAutomatically = true; var lastStopped: ((Boolean)->Unit)? = null }
|
||||
fun aecAvailability() = AecAvailability.UNKNOWN
|
||||
fun start(onFrame: (ByteArray) -> Unit, onError: (Exception) -> Unit, onDiagnostic: (String) -> Unit = {}) { starts++; lastFrame = onFrame; lastError = onError; onDiagnostic("AudioRecord initialization ok") }
|
||||
fun stopAndConfirm(confirmed: (Boolean) -> Unit) { lastStopped = confirmed; if(confirmStopsAutomatically) confirmed(true) }
|
||||
fun stop() {}
|
||||
fun release() {}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import com.gorios.lanvoice.audio.*
|
||||
import com.gorios.lanvoice.net.*
|
||||
|
||||
fun checkCallControls() {
|
||||
checkActionSession()
|
||||
val states = mutableListOf<VoiceUiState>()
|
||||
val session = VoiceSession("localhost",5011,states::add)
|
||||
fun set(name: String,value: Any) { session.javaClass.getDeclaredField(name).apply { isAccessible=true }.set(session,value) }
|
||||
|
||||
@@ -8,13 +8,14 @@ class Payload(private val ok: Boolean = true, private val turn: Long? = null, pr
|
||||
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 fields[key]
|
||||
}
|
||||
enum class EventKind { AUTH, HELLO, ERROR, HISTORY, UNKNOWN, LISTEN, VAD, STT, LLM, TTS, ABORT, REPLY_EMOTION }
|
||||
enum class EventKind { AUTH, HELLO, ERROR, HISTORY, UNKNOWN, LISTEN, VAD, STT, LLM, TTS, ABORT, REPLY_EMOTION, EXPRESSION_PREPARE, ACTION, SPEECH }
|
||||
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 actionStatus(value: com.gorios.lanvoice.avatar.ActionStatus) = "action_status"
|
||||
fun faceCue(turn: Long, observation: com.gorios.lanvoice.expression.FaceCueObservation, age: Long) = "face_cue"
|
||||
fun hello() = "hello"
|
||||
fun hello(actionPackSha: String? = null) = "hello"
|
||||
fun listen(start: Boolean) = "listen"
|
||||
fun abort(turn: Long) = "abort"
|
||||
fun playbackDrained(turn: Long) = "drained"
|
||||
|
||||
Reference in New Issue
Block a user