Keep short commands after wake activation

This commit is contained in:
2026-11-11 12:38:39 +03:00
parent 42b9412f9c
commit 1d68638598
+9 -2
View File
@@ -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))