Files
baji-vc/tests/avatar/IdleVariantCheck.kt
T

88 lines
5.4 KiB
Kotlin

import com.gorios.lanvoice.avatar.*
import com.gorios.lanvoice.dialogue.RoleEmotion
/** Actual driver callbacks, synthetic bodies; no naturalness or device claim. */
fun idleVariantCheck() {
var checks=0
class Port: CompositeMediaPort {
lateinit var pack: ContinuousAvatarPack
lateinit var frame: (BodyFrameKey,Boolean)->Unit
lateinit var ended: ()->Unit
var talking=false;var closed=false;var loop=false
override fun prepare(pack: ContinuousAvatarPack,entryFrame: Int,mouth: Boolean,loop: Boolean,
frame: (BodyFrameKey,Boolean)->Unit,ended: ()->Unit,failed: ()->Unit) {
this.pack=pack;this.frame=frame;this.ended=ended;this.loop=loop
}
override fun advance() {}
override fun mouth(talk: Boolean,generation: Long,revision: Long) { talking=talk }
override fun close(released: ()->Unit) { closed=true;released() }
fun emit(i: Int,ordinal: Long=0) { frame(BodyFrameKey(i,ordinal,pack.body.ptsUs[i]),!talking) }
}
val base=mediaFixtureIndex()
val index=base.copy(actionPack=null,visuals=base.visuals.map {
if(it.id=="neutral") it else it.copy(emotion=RoleEmotion.NEUTRAL)
})
val music=object: MusicMediaPort {
override fun prepare(media: ActionMedia,ready: ()->Unit,firstFrame: ()->Unit,ended: ()->Unit,failed: ()->Unit) { error("No music") }
override fun start() { error("No music") }
override fun close(released: ()->Unit) { released() }
}
val ports=mutableListOf<Port>();val trace=mutableListOf<String>()
val driver=ConversationMediaDriver(index,{ Port().also(ports::add) },music,{}, { phase,_->trace.add(phase) },chooseIdle={0},chooseIdleCycles={2})
driver.beginTurn(7);driver.start();val fallback=ports.single()
(0..95).forEach { fallback.emit(it) }
check(ports.size==1);checks++ // No arbitrary phase departure.
fallback.emit(96);check(ports.size==1);checks++
(0..95).forEach { fallback.emit(it,1) };check(ports.size==1);checks++
fallback.emit(96,1);check(ports.size==3 && trace.contains("idle_variant_queued"));checks++
fun bridgeTo(target: Port,bridge: Port) {
target.emit(0);bridge.emit(0)
check(trace.last()=="bridge" && !bridge.loop);checks++
(1 until bridge.pack.body.frameCount).forEach { bridge.emit(it) };bridge.ended()
check(bridge.closed && driver.currentPackageId!=null);checks++
}
val idle1=ports[1];bridgeTo(idle1,ports[2])
check(driver.currentPackageId=="happy" && driver.visualStatus=="neutral_idle_variant");checks++
(1 until idle1.pack.body.frameCount).forEach { idle1.emit(it) }
check(ports.size==3);checks++
(0 until idle1.pack.body.frameCount).forEach { idle1.emit(it,1) }
check(trace.contains("idle_variant_return_queued") && ports.size==5);checks++
val returned=ports[3];bridgeTo(returned,ports[4])
(1..96).forEach { returned.emit(it) }
check(ports.size==5);checks++
(0..96).forEach { returned.emit(it,1) }
val idle2=ports[5];bridgeTo(idle2,ports[6])
check(driver.currentPackageId=="sad");checks++ // Pick0 still excludes previous idle1.
driver.intent(mediaReply(RoleEmotion.NEUTRAL),true)
check(idle2.talking && ports.size==9);checks++ // Audio continues on current own body while returning.
(1 until idle2.pack.body.frameCount).forEach { idle2.emit(it) }
val speakingFallback=ports[7];bridgeTo(speakingFallback,ports[8])
check(speakingFallback.talking);checks++
(1..96).forEach { speakingFallback.emit(it) }
check(ports.size==9);checks++ // No variation during active TALK.
driver.stop {};val count=trace.size
idle2.emit(0);ports[8].ended();check(trace.size==count && ports.all { it.closed });checks++
val three=mutableListOf<Port>()
val slow=ConversationMediaDriver(index,{ Port().also(three::add) },music,{},chooseIdle={0},chooseIdleCycles={3})
slow.beginTurn(7);slow.start()
repeat(2) { cycle -> (0..96).forEach { three[0].emit(it,cycle.toLong()) };check(three.size==1);checks++ }
(0..95).forEach { three[0].emit(it,2) };check(three.size==1);checks++
three[0].emit(96,2);check(three.size==3);checks++;slow.stop {}
// Missing bridge mouth prevents idle activation even with valid own body layers.
val noMouth=index.copy(edges=index.edges.map { if(it.nativeLoop) it else it.copy(mouthRuntime=null) })
val guarded=mutableListOf<Port>()
val other=ConversationMediaDriver(noMouth,{ Port().also(guarded::add) },music,{},chooseIdle={0},chooseIdleCycles={2})
other.beginTurn(7);other.start();(0..96).forEach { guarded[0].emit(it) }
check(guarded.size==1);checks++;other.stop {}
// A retained happy/sad expression must not turn neutral when speech ends.
val expressive=mutableListOf<Port>()
val retained=ConversationMediaDriver(base,{ Port().also(expressive::add) },music,{},chooseIdle={0},chooseIdleCycles={2})
retained.beginTurn(7);retained.start();retained.intent(mediaReply(RoleEmotion.HAPPY),false)
(0..96).forEach { expressive[0].emit(it) };expressive[1].emit(0);expressive[2].emit(0)
expressive[2].emit(1);expressive[2].emit(2);expressive[2].ended()
(1..48).forEach { expressive[1].emit(it) }
check(retained.currentPackageId=="happy" && expressive.size==3);checks++;retained.stop {}
println("PASS: $checks idle variant driver assertions: complete cycle/legal own-mouth bridges, different N/fps, no consecutive repeat, TALK priority, release/late callbacks, expression retention; fixtures only")
}