// Fenrir console screen reader. // Copyright (c) 2026 Storm Dragon // SPDX-License-Identifier: GPL-3.0-or-later // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation, either version 3 of the License, or (at your option) // any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details. // // You should have received a copy of the GNU General Public License along with // this program. If not, see . package speech import ( "bytes" "log/slog" "strings" "testing" "time" ) func TestTimingDiagnosticsExcludeSpeechText(t *testing.T) { var output bytes.Buffer previousLogger := slog.Default() slog.SetDefault(slog.New(slog.NewTextHandler(&output, &slog.HandlerOptions{Level: slog.LevelDebug}))) defer slog.SetDefault(previousLogger) fake := new_recording_transport() s := New(fake) defer s.Close() const privateText = "private speech fixture" s.Interrupt() s.Say(privateText) wait_event(t, fake.changed, "sent:"+privateText) s.Close() if strings.Contains(output.String(), privateText) { t.Fatal("timing diagnostics included speech text") } for _, stage := range []string{"speech queue wait", "speech send", "speech cancel barrier"} { if !strings.Contains(output.String(), stage) { t.Fatalf("missing timing stage %q", stage) } } } type latencyTransport struct { sent chan struct{} } func (f *latencyTransport) Say(string) error { f.sent <- struct{}{}; return nil } func (f *latencyTransport) Cancel() error { time.Sleep(time.Millisecond); return nil } func (f *latencyTransport) Close() {} func (f *latencyTransport) Set_pitch(int) error { return nil } func (f *latencyTransport) Configure(Parameters) error { return nil } // Model a fixed acknowledgement cost to expose unnecessary cancellation waits. // This measures admission/transport scheduling, not audible speech latency. func BenchmarkIdleInterruptToSpeech(b *testing.B) { fake := &latencyTransport{sent: make(chan struct{})} s := New(fake) defer s.Close() for b.Loop() { s.Interrupt() s.Say("response") <-fake.sent } }