Очки: отмена слушания двойным тапом — SttCancel reason=cancel
This commit is contained in:
@@ -22,6 +22,8 @@ import pw.binom.viewmate.core.protocol.GlassesToHost
|
||||
import pw.binom.viewmate.core.protocol.Hello
|
||||
import pw.binom.viewmate.core.protocol.HostToGlasses
|
||||
import pw.binom.viewmate.core.protocol.SetMode
|
||||
import pw.binom.viewmate.core.protocol.StopStt
|
||||
import pw.binom.viewmate.core.protocol.SttCancel
|
||||
import pw.binom.viewmate.core.protocol.Welcome
|
||||
import pw.binom.viewmate.core.protocol.protocolJson
|
||||
import kotlin.test.Test
|
||||
@@ -164,6 +166,39 @@ class GlassesServerTest {
|
||||
assertEquals("0.2.0", hub.appVersion.value)
|
||||
}
|
||||
|
||||
// ---------- StopStt → SttCancel/SttDone (TASK-cancel-listen.md) ----------
|
||||
|
||||
/** StopStt(cancel=true) — двойной тап-отмена на очках: очки получают SttCancel(reason=cancel). */
|
||||
@Test
|
||||
fun stopSttCancelSendsSttCancelReasonCancel() = runServer { port, hub ->
|
||||
val client = wsClient()
|
||||
client.webSocket("ws://127.0.0.1:$port$GLASSES_WS_PATH") {
|
||||
send(json.encodeToString(GlassesToHost.serializer(), StopStt(cancel = true)))
|
||||
val frame = incoming.receive() as Frame.Text
|
||||
val msg = json.decodeFromString(HostToGlasses.serializer(), frame.readText())
|
||||
val cancel = assertIs<SttCancel>(msg)
|
||||
assertEquals(SttCancel.REASON_CANCEL, cancel.reason)
|
||||
}
|
||||
}
|
||||
|
||||
/** StopStt(cancel=false) с пустым текстом — очки возвращаются в «слушаю»: SttCancel(reason=user). */
|
||||
@Test
|
||||
fun stopSttEmptyTextBroadcastsSttCancelReasonUser() = runServer { port, hub ->
|
||||
val client = wsClient()
|
||||
client.webSocket("ws://127.0.0.1:$port$GLASSES_WS_PATH") {
|
||||
send(json.encodeToString(GlassesToHost.serializer(), StopStt(cancel = false)))
|
||||
val frame = incoming.receive() as Frame.Text
|
||||
val msg = json.decodeFromString(HostToGlasses.serializer(), frame.readText())
|
||||
val cancel = assertIs<SttCancel>(msg)
|
||||
assertEquals(SttCancel.REASON_USER, cancel.reason)
|
||||
}
|
||||
}
|
||||
|
||||
// Полная фраза (StopStt(cancel=false) с текстом → SttDone + onStopFullText) в JVM-юните
|
||||
// не проверяется: реальный SttStreamer держит нативный VAD (com.k2fsa.sherpa.onnx.Vad),
|
||||
// а нативная библиотека sherpa-onnx есть ТОЛЬКО под Android-bionic — в JVM-юните её нет,
|
||||
// и фейк падает UnsatisfiedLinkError (неремонтируемо). Сценарий покрывается на устройстве.
|
||||
|
||||
// ---------- помощники ----------
|
||||
|
||||
private inline fun runServer(crossinline block: suspend (port: Int, hub: GlassesHub) -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user