End of speech: digital silence is a pause, a steady voice is not the room
Review S2, S3, S6. A zero level after sound was skipped as "no microphone yet", so speech into a headset that gates its noise to exact zeros never counted a pause and ran to the limit. Once a floor is known a zero tick is quiet. Listening that began in the middle of a sentence with shallow dips let the floor creep up to the voice: no speech was ever seen and it gave up as "nothing said" while the person talked. The floor now rises only in calm moments (the last half second within half again of itself), a first sound louder than any room is kept as a guess until a dip or a calm moment shows the room, and sound that stays above the floor without being steady is speech. Words count as speech from four ticks above the room, not two. phoneWatch takes how long ago the recogniser last gave a sign of somebody speaking: no words is no longer "nothing said" while it reports speech. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+114
-25
No files matched your search
@@ -44,12 +44,15 @@ class EndOfSpeechTest {
|
||||
private fun still(level: Float, ticks: Int): List<Float> = List(ticks) { level }
|
||||
|
||||
/** Ended as said, a pause after [start]'s last sound: not before it was over, and not long after. */
|
||||
private fun assertEndsAfter(start: List<Float>, ended: Ended) {
|
||||
private fun assertEndsAfter(start: List<Float>, ended: Ended, late: Long = 400) {
|
||||
val over = start.size * EndOfSpeech.TICK_MS
|
||||
assertEquals(Verdict.Said, ended.verdict)
|
||||
assertTrue("ended at ${ended.ms}, speech over at $over", ended.ms > over + EndOfSpeech.PAUSE_MS - 400 && ended.ms <= over + EndOfSpeech.PAUSE_MS + 400)
|
||||
assertTrue("ended at ${ended.ms}, speech over at $over", ended.ms > over + EndOfSpeech.PAUSE_MS - 400 && ended.ms <= over + EndOfSpeech.PAUSE_MS + late)
|
||||
}
|
||||
|
||||
/** A voice that never dips far: its quietest moments are six tenths of its loudest. One second. */
|
||||
private fun steadyVoice(peak: Float): List<Float> = listOf(1.0f, 0.7f, 0.9f, 0.6f, 1.0f, 0.8f, 0.65f, 0.95f, 0.75f, 0.6f).map { it * peak }
|
||||
|
||||
@Test
|
||||
fun aSilentRoomWithNothingSaidGivesUpSoon() {
|
||||
assertEquals(Ended(Verdict.Nothing, EndOfSpeech.NOTHING_SAID_MS), listen(emptyList(), still(0.001f, 1)))
|
||||
@@ -76,7 +79,8 @@ class EndOfSpeechTest {
|
||||
@Test
|
||||
fun speechInANoisyRoomEndsAfterThePauseToo() {
|
||||
val start = noise(0.03f) + voice(0.12f)
|
||||
assertEndsAfter(start, listen(start, noise(0.03f)))
|
||||
// The room is louder than the first guess allows for: found a moment after the voice ends.
|
||||
assertEndsAfter(start, listen(start, noise(0.03f)), late = 800)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,6 +99,27 @@ class EndOfSpeechTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun silenceFromAHeadsetThatGatesItsNoiseIsAPause() {
|
||||
// After speech the microphone gives exact zeros: that is quiet, not "no microphone".
|
||||
val start = still(0.001f, 5) + voice(0.06f)
|
||||
assertEndsAfter(start, listen(start, still(0f, 1)))
|
||||
val atOnce = voice(0.06f)
|
||||
assertEndsAfter(atOnce, listen(atOnce, still(0f, 1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listeningThatBeginsInTheMiddleOfASentenceHearsIt() {
|
||||
// The wake word's shape: the person goes straight on, and for eight seconds the voice
|
||||
// never dips far. It must not become "the room", nor end as "nothing said" at five.
|
||||
for (peak in listOf(0.035f, 0.05f, 0.1f)) {
|
||||
var start = emptyList<Float>()
|
||||
repeat(8) { start = start + steadyVoice(peak) }
|
||||
assertEndsAfter(start, listen(start, still(0.002f, 1)))
|
||||
assertEndsAfter(start, listen(start, still(0.004f, 1)))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aShortWordIsSpeech() {
|
||||
val start = still(0.001f, 10) + listOf(0.03f, 0.05f, 0.04f, 0.01f)
|
||||
@@ -173,4 +198,15 @@ class EndOfSpeechTest {
|
||||
assertEquals(PhoneWatch.Finish, phoneWatch(EndOfSpeech.LONGEST_MS, anyWords = true, sameForMs = 0))
|
||||
assertEquals(PhoneWatch.Take, phoneWatch(EndOfSpeech.LONGEST_MS + PHONE_GRACE_MS, anyWords = true, sameForMs = 0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRecogniserThatShowsNoWordsWhileOneSpeaksIsNotGivenUpOn() {
|
||||
// No partial results, but it said speech began and its level is loud: somebody speaks.
|
||||
assertEquals(PhoneWatch.Wait, phoneWatch(12_000, anyWords = false, sameForMs = 12_000, silentForMs = 300))
|
||||
// Quiet for a good while after that: asked for what it has, then given up on.
|
||||
assertEquals(PhoneWatch.Finish, phoneWatch(20_000, anyWords = false, sameForMs = 20_000, silentForMs = PHONE_NOTHING_SAID_MS))
|
||||
assertEquals(PhoneWatch.GiveUp, phoneWatch(20_000, anyWords = false, sameForMs = 20_000, silentForMs = PHONE_NOTHING_SAID_MS + PHONE_GRACE_MS))
|
||||
// Words that stopped changing while the level is still loud: not cut off yet.
|
||||
assertEquals(PhoneWatch.Wait, phoneWatch(20_000, anyWords = true, sameForMs = EndOfSpeech.SAME_WORDS_MS, silentForMs = 200))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user