Files

30 lines
840 B
Go

package callflow
import (
"context"
"testing"
"time"
)
func TestCaptureTurnWaitsForSpeechAndStopsOnSilence(t *testing.T) {
silence := make([]byte, 640)
voice := make([]byte, 640)
for i := 0; i < len(voice); i += 2 {
voice[i] = 0xE8
voice[i+1] = 0x03 // 1000, little-endian PCM16
}
session := NewMemorySession(append(append(append([]byte{}, silence...), voice...), silence...))
captured, err := captureTurn(context.Background(), session, CaptureConfig{
FirstSpeechTimeout: 20 * time.Millisecond,
MaxDuration: 20 * time.Millisecond,
EndSilence: time.Millisecond,
VoiceThreshold: 100,
})
if err != nil {
t.Fatal(err)
}
if len(captured) < len(voice) || len(captured) >= len(silence)+len(voice)+len(silence) {
t.Fatalf("captured=%d want speech and bounded trailing silence", len(captured))
}
}