From 1d68638598b39d6c30890fd7839c540c09e244e4 Mon Sep 17 00:00:00 2001 From: chexit Date: Wed, 11 Nov 2026 12:38:39 +0300 Subject: [PATCH] Keep short commands after wake activation --- station/main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/station/main.go b/station/main.go index a20d704..e70fc51 100644 --- a/station/main.go +++ b/station/main.go @@ -289,7 +289,8 @@ func exchange(url, token string, live *liveReader, fileAudio []byte, wakeAudio [ const prerollSamples = rate pre := make([]int16, 0, prerollSamples+hop) pre = append(pre, wakeAudio...) - var frames, lastVoice, voiced, sent int + var frames, voiced, sent int + lastVoice := -9 var peakRMS float64 heard := false for ; frames < int(max/(10*time.Millisecond)); frames++ { @@ -306,8 +307,14 @@ func exchange(url, token string, live *liveReader, fileAudio []byte, wakeAudio [ s := audio.pcm level := rms(s) peakRMS = math.Max(peakRMS, level) + voiceStart := false if level >= threshold { voiced++ + // Short commands after activation can have quiet gaps between + // syllables. Require two voiced frames within 80 ms or a strong + // frame outside the immediate tail of the wake word. + voiceStart = voiced >= 3 || wakeAudio != nil && + (frames-lastVoice <= 8 || frames >= 3 && level >= 2*threshold) lastVoice = frames } else { voiced = 0 @@ -318,7 +325,7 @@ func exchange(url, token string, live *liveReader, fileAudio []byte, wakeAudio [ copy(pre, pre[len(pre)-prerollSamples:]) pre = pre[:prerollSamples] } - if voiced < 3 { + if !voiceStart { continue } _ = c.SetWriteDeadline(time.Now().Add(2 * time.Second))