Two follow-ups from hands-free testing:
- Audio cues had no off-switch: empty sound fields fall back to the freedesktop
system chime, so wakeword/recording always made noise. Add a [sounds] enabled
master flag (default true) exposed as "Play audio cues" in Settings → Input.
When off, _play_cue/_play_sound are no-ops — fully silent operation.
- The VAD level meter (sounddevice/PortAudio) leaked harmless thread-teardown
errors ("pthread_join ... failed", "PaUnixThread_Terminate ... failed") to the
terminal on every clip end. PortAudio writes these straight to fd 2, so wrap
the stream open/close in a fd-level stderr suppressor (_quiet_c_stderr).
Tests: cue gating respects the master switch (16 passed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
"""Hands-free (wakeword) sessions must stay quiet.
|
|
|
|
Regression tests for two reported bugs:
|
|
1. The wakeword produced desktop notifications when the user was away — most
|
|
notably a "Busy" storm from repeated false detections arriving while a
|
|
previous clip was still transcribing.
|
|
2. A hands-free session's errors popped up as critical notifications.
|
|
"""
|
|
|
|
import blitztext.daemon as daemon_mod
|
|
from blitztext.config import Config
|
|
from blitztext.daemon import Daemon
|
|
|
|
|
|
def _make_daemon(monkeypatch):
|
|
# Don't probe real audio devices when constructing the daemon.
|
|
monkeypatch.setattr(daemon_mod, "detect_recorder", lambda pref="auto": "pw-record")
|
|
return Daemon(Config())
|
|
|
|
|
|
def test_dnotify_suppressed_in_silent_session(monkeypatch):
|
|
calls = []
|
|
monkeypatch.setattr(daemon_mod, "notify", lambda *a, **k: calls.append((a, k)))
|
|
d = _make_daemon(monkeypatch)
|
|
|
|
d._session_silent = True
|
|
d._dnotify("Recording", "…")
|
|
assert calls == [], "per-dictation notifications must be suppressed for hands-free sessions"
|
|
|
|
d._session_silent = False
|
|
d._dnotify("Recording", "…")
|
|
assert len(calls) == 1, "keyboard/GUI sessions should still notify"
|
|
|
|
|
|
def test_on_wakeword_starts_a_silent_session(monkeypatch):
|
|
started = {}
|
|
d = _make_daemon(monkeypatch)
|
|
monkeypatch.setattr(d, "start_dictation", lambda wf=None, silent=False: started.update(wf=wf, silent=silent))
|
|
|
|
d._on_wakeword()
|
|
|
|
assert started.get("silent") is True
|
|
assert started.get("wf") is d._route_workflow
|
|
|
|
|
|
def test_audio_cues_master_switch(monkeypatch):
|
|
import blitztext.sound as sound_mod
|
|
plays = []
|
|
monkeypatch.setattr(sound_mod, "play", lambda *a, **k: plays.append((a, k)))
|
|
d = _make_daemon(monkeypatch)
|
|
|
|
d.cfg.sounds_enabled = False
|
|
d._play_cue("before")
|
|
d._play_sound("device-removed")
|
|
assert plays == [], "no cue should play when audio cues are disabled"
|
|
|
|
d.cfg.sounds_enabled = True
|
|
d._play_cue("before")
|
|
d._play_sound("device-removed")
|
|
assert len(plays) == 2, "cues should play when enabled"
|
|
|
|
|
|
def test_wakeword_while_busy_does_not_notify(monkeypatch):
|
|
"""The away-from-keyboard "Busy" storm: a detection arriving while the
|
|
previous clip is still being processed must be ignored silently."""
|
|
calls = []
|
|
monkeypatch.setattr(daemon_mod, "notify", lambda *a, **k: calls.append((a, k)))
|
|
d = _make_daemon(monkeypatch)
|
|
d._prepared = True # model "loaded"
|
|
d._busy = True # still transcribing the previous clip
|
|
|
|
d._on_wakeword()
|
|
|
|
assert calls == [], "a wakeword hit while busy must not pop a 'Busy' notification"
|
|
assert d.is_recording is False, "no new session should start while busy"
|