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.PCM) < len(voice) || len(captured.PCM) >= len(silence)+len(voice)+len(silence) || captured.Window.StartedAt.IsZero() || captured.Window.EndedAt.Before(captured.Window.StartedAt) { t.Fatalf("capture lost voice, duration boundary or observed times: pcm=%d window=%+v", len(captured.PCM), captured.Window) } }