voice: require the wake word for every command
Drop the post-reply follow-up window: capture no longer accepts an utterance without the wake word after a result, so the front end never keeps listening on its own. Removes follow_up_window_s from the config/README/AGENTS/bootstrap docs and updates the tests (a reply no longer arms capture).
This commit is contained in:
1 parent
a388c292bc
commit
ff94ea938c
6 files changed
+30
-46
No files matched your search
@@ -293,8 +293,7 @@ voice_transport.py
|
||||
always-on wake word (openWakeWord), VAD endpointing
|
||||
(webrtcvad, energy fallback), speech-to-text (faster-whisper)
|
||||
and text-to-speech (Piper) over `sounddevice`; half-duplex
|
||||
(capture discarded while speaking) with a follow-up window so a
|
||||
reply can be answered without the wake word. Every heavy dep is
|
||||
(capture discarded while speaking). Every heavy dep is
|
||||
lazy-imported, keeping the module stdlib-only; the engine
|
||||
interfaces are plain classes so tests inject fakes. Knows
|
||||
nothing about the scheduler or the gateway.
|
||||
@@ -558,8 +557,8 @@ CLI, unit tests (24) + integration tests (2).
|
||||
work through `GatewayService` unchanged — a spoken command is just text from
|
||||
`voice:<chat_id>`, and every reply is spoken. No remote peer and no allowlist
|
||||
(physical mic access is the authorization). Half-duplex: capture is discarded
|
||||
while a reply is speaking (no barge-in yet); after each reply a
|
||||
`follow_up_window_s` accepts the next utterance without the wake word. The
|
||||
while a reply is speaking (no barge-in yet); the wake word is required before
|
||||
every command. The
|
||||
whole voice stack is optional and lazy-imported (`requirements/voice.txt`,
|
||||
pinned separately from the engine set since it is hardware-dependent); the
|
||||
gateway refuses to start with an install hint. `bootstrap.sh --voice`
|
||||
@@ -1174,8 +1173,7 @@ CLI, unit tests (24) + integration tests (2).
|
||||
pause before the command does not end the capture (then `vad.silence_ms`).
|
||||
**Half-duplex**: capture frames are discarded while a
|
||||
reply is speaking, so the agent never transcribes itself (no barge-in yet);
|
||||
after a reply a `follow_up_window_s` accepts the next utterance without the
|
||||
wake word, so answering a question is conversational. `max_speak_chars`
|
||||
the wake word is required before every command. `max_speak_chars`
|
||||
truncates long replies before speaking, and a short sine `cue` beep plays on
|
||||
wake (optionally again on transcription) so the user knows they were heard.
|
||||
**Result-only output**: `VoiceAdapter.result_only` (default true; per-platform
|
||||
@@ -1278,7 +1276,7 @@ CLI, unit tests (24) + integration tests (2).
|
||||
`simplex.send_message`, and
|
||||
`simplex.connect_link`. `tests/test_voice_gateway.py` drives the voice loop
|
||||
with injected fake engines (wake gating, endpointing, half-duplex,
|
||||
follow-up window, `speak` truncation/failure, adapter + CLI wiring) — no
|
||||
`speak` truncation/failure, adapter + CLI wiring) — no
|
||||
hardware, network, or heavy packages. `tests/test_voice_record.py` covers the
|
||||
recording helpers (`semif_agent/voice_train.py`) — prompt loading, WAV I/O,
|
||||
level math, the silence-endpointing loop, and the LJSpeech dataset writer —
|
||||
|
||||
@@ -513,7 +513,7 @@ Key blocks:
|
||||
| `queue` | `max_size` |
|
||||
| `skill_bodies` / `skill_seeds` / `log` / `trace` / `category_registry` | runtime paths (anchored to the checkout) |
|
||||
| `gateway.simplex` | command gateway: ws_url, allowlist, batching |
|
||||
| `gateway.voice` | voice gateway: wake/STT/TTS engines + models, audio devices, VAD, follow-up window |
|
||||
| `gateway.voice` | voice gateway: wake/STT/TTS engines + models, audio devices, VAD |
|
||||
| `bridges.simplex` | forwarding bridge: host/port/token/ws_url |
|
||||
| `bridges.llm` | LLM bridge: host/port/token (model comes from `llm`) |
|
||||
| `bridges.nextcloud` | Nextcloud bridge: host/port/token + connection (url/username/app_password/defaults) |
|
||||
@@ -687,10 +687,8 @@ python -m semif_agent.cli gateway --platform voice
|
||||
short multi-note "bling" (`cue.submit_notes`, each entry
|
||||
`[frequency_hz, duration_ms]`, spaced by `cue.note_gap_ms`) plays once the
|
||||
utterance is transcribed. (Set `cue.submit_notes` to `[]` and
|
||||
`cue.submit_frequency > 0` for the older single submit beep.) After a reply, the next
|
||||
utterance is accepted **without** the wake word for `follow_up_window_s`, so
|
||||
answering a question is conversational. After the wake word, capture waits
|
||||
`listen_timeout_s` for the command to begin, so a pause before speaking
|
||||
`cue.submit_frequency > 0` for the older single submit beep.) After the wake
|
||||
word, capture waits `listen_timeout_s` for the command to begin, so a pause before speaking
|
||||
(e.g. while the cue beep plays) does not truncate it. `max_speak_chars`
|
||||
truncates long
|
||||
replies before speaking. `result_only` (default true for voice) speaks only the
|
||||
|
||||
+1
-2
@@ -217,7 +217,7 @@
|
||||
"text_batch_delay": 0.8
|
||||
},
|
||||
"voice": {
|
||||
"_comment": "Voice command adapter: a local microphone front end with wake word + speech-to-text + text-to-speech. Requires the optional voice stack (requirements/voice.txt; sounddevice + openwakeword + faster-whisper + piper-tts + onnxruntime; the system needs libportaudio2). Lazy-imported; the gateway refuses to start with an install hint. Runs best in the user's audio session (foreground `gateway --platform voice`), not a headless systemd user service. Audio is 16 kHz mono int16; capture/playback run at the device's native rate and are resampled to/from 16 kHz (capture_sample_rate/output_sample_rate override it; 0 = the device default). wake.model is an openWakeWord model name or path (official models download into the venv and resolve by name; a pinned community model such as the default 'hey_computer' is fetched into model_dir, .runtime/voice/wake); stt.model is a faster-whisper size/path (cached under .runtime/hf); tts.voice is a Piper voice id or path (bootstrap downloads it under .runtime/voice/tts). After each reply the next utterance is accepted without the wake word for follow_up_window_s. After the wake word, listen_timeout_s is how long to wait for the command to start before giving up, so a pause before speaking does not truncate it. result_only speaks just the skill's result line (dropping queue/urgency bookkeeping and the `<skill>: ok —` wrapper) instead of the full scheduler output; set false for the complete text. max_speak_chars truncates long replies before speaking. chat_id identifies the single local session; home_channel defaults to it so timers/repair offers are spoken too. A stalled capture stream (the PortAudio callback stops delivering frames) is detected via audio.read_timeout_s and recovered by closing and reopening the input after audio.stall_timeout_s, so the front end no longer hangs silently. Utterances run on a worker thread (not the audio thread), so a slow or failing task neither stops the mic being read nor kills the front end.",
|
||||
"_comment": "Voice command adapter: a local microphone front end with wake word + speech-to-text + text-to-speech. Requires the optional voice stack (requirements/voice.txt; sounddevice + openwakeword + faster-whisper + piper-tts + onnxruntime; the system needs libportaudio2). Lazy-imported; the gateway refuses to start with an install hint. Runs best in the user's audio session (foreground `gateway --platform voice`), not a headless systemd user service. Audio is 16 kHz mono int16; capture/playback run at the device's native rate and are resampled to/from 16 kHz (capture_sample_rate/output_sample_rate override it; 0 = the device default). wake.model is an openWakeWord model name or path (official models download into the venv and resolve by name; a pinned community model such as the default 'hey_computer' is fetched into model_dir, .runtime/voice/wake); stt.model is a faster-whisper size/path (cached under .runtime/hf); tts.voice is a Piper voice id or path (bootstrap downloads it under .runtime/voice/tts). After the wake word, listen_timeout_s is how long to wait for the command to start before giving up, so a pause before speaking does not truncate it. result_only speaks just the skill's result line (dropping queue/urgency bookkeeping and the `<skill>: ok —` wrapper) instead of the full scheduler output; set false for the complete text. max_speak_chars truncates long replies before speaking. chat_id identifies the single local session; home_channel defaults to it so timers/repair offers are spoken too. A stalled capture stream (the PortAudio callback stops delivering frames) is detected via audio.read_timeout_s and recovered by closing and reopening the input after audio.stall_timeout_s, so the front end no longer hangs silently. Utterances run on a worker thread (not the audio thread), so a slow or failing task neither stops the mic being read nor kills the front end.",
|
||||
"enabled": false,
|
||||
"chat_id": "voice",
|
||||
"display_name": "voice",
|
||||
@@ -225,7 +225,6 @@
|
||||
"reply_prefix": "",
|
||||
"result_only": true,
|
||||
"max_speak_chars": 600,
|
||||
"follow_up_window_s": 5.0,
|
||||
"listen_timeout_s": 3.0,
|
||||
"cue": {
|
||||
"_comment": "Audible feedback. A short sine beep plays when the wake word fires so you know you're being heard; submit_notes is a short multi-note 'bling' played once the utterance is transcribed (each entry [frequency_hz, duration_ms], separated by note_gap_ms of silence). Set submit_notes to [] and submit_frequency > 0 for the older single submit beep, or leave both empty/0 for no submit sound. volume is 0..1.",
|
||||
|
||||
@@ -643,8 +643,8 @@ Voice command gateway (wake word + speech-to-text + text-to-speech):
|
||||
the foreground (it needs your audio session; it is NOT a systemd unit):
|
||||
HF_HOME="$HF_CACHE" "$PYTHON" -m semif_agent.cli gateway --platform voice
|
||||
- Say the wake word (gateway.voice.wake.model, default 'hey_computer' — phrase
|
||||
"Hey Computer") and speak; the reply is spoken back. After each reply the
|
||||
next utterance needs no wake word for gateway.voice.follow_up_window_s.
|
||||
"Hey Computer") and speak; the reply is spoken back. The wake word is
|
||||
required before every command (no post-reply follow-up listening).
|
||||
- If the mic or speaker is silent/quiet, set the ALSA mixer (PortAudio has no
|
||||
volume control) and persist it:
|
||||
alsamixer # or: amixer -c <card> sset 'Speaker' unmute
|
||||
|
||||
@@ -17,9 +17,6 @@ resampling is done in the loop.
|
||||
Design notes:
|
||||
- **Half-duplex.** Capture frames are discarded while a reply is being spoken,
|
||||
so the agent never transcribes its own voice (no barge-in yet).
|
||||
- **Follow-up window.** After a reply, the next utterance is accepted without
|
||||
the wake word for `follow_up_window_s`, so answering a question is
|
||||
conversational.
|
||||
- The engine interfaces are plain classes so tests can inject fakes and drive
|
||||
the loop without hardware or the optional packages.
|
||||
"""
|
||||
@@ -672,7 +669,6 @@ class VoiceDaemon:
|
||||
self.initial_silence_ms = max(
|
||||
int(vad_cfg.get("initial_silence_ms", 1500) or 0), self.vad_silence_ms
|
||||
)
|
||||
self.follow_up_window = float(cfg.get("follow_up_window_s", 5.0) or 0.0)
|
||||
self.max_speak_chars = int(cfg.get("max_speak_chars", 600) or 0)
|
||||
cue = cfg.get("cue", {}) or {}
|
||||
self.cue_enabled = bool(cue.get("enabled", True))
|
||||
@@ -693,7 +689,6 @@ class VoiceDaemon:
|
||||
self._on_utterance: UtteranceHandler | None = None
|
||||
self._stop = threading.Event()
|
||||
self._speaking = threading.Event()
|
||||
self._follow_until = 0.0
|
||||
|
||||
# ---- requirements ----
|
||||
|
||||
@@ -768,23 +763,19 @@ class VoiceDaemon:
|
||||
continue
|
||||
if self._speaking.is_set():
|
||||
continue
|
||||
armed = time.time() < self._follow_until
|
||||
wait_for_speech_ms = 0
|
||||
if not armed:
|
||||
score = engines.wake.score(pcm)
|
||||
if score < self.wake_threshold:
|
||||
continue
|
||||
self._event("voice_wake", score=round(float(score), 3))
|
||||
try:
|
||||
engines.wake.reset()
|
||||
except Exception:
|
||||
pass
|
||||
self._cue(self.cue_frequency, self.cue_duration_ms)
|
||||
# Wait for the command to start rather than assuming it is
|
||||
# glued to the wake word (the wake frame + a natural pause are
|
||||
# discarded so the command is not truncated).
|
||||
wait_for_speech_ms = self.listen_timeout_ms
|
||||
self._follow_until = 0.0
|
||||
score = engines.wake.score(pcm)
|
||||
if score < self.wake_threshold:
|
||||
continue
|
||||
self._event("voice_wake", score=round(float(score), 3))
|
||||
try:
|
||||
engines.wake.reset()
|
||||
except Exception:
|
||||
pass
|
||||
self._cue(self.cue_frequency, self.cue_duration_ms)
|
||||
# Wait for the command to start rather than assuming it is glued to
|
||||
# the wake word (the wake frame + a natural pause are discarded so
|
||||
# the command is not truncated).
|
||||
wait_for_speech_ms = self.listen_timeout_ms
|
||||
utterance = self._collect(engines, pcm, wait_for_speech_ms=wait_for_speech_ms)
|
||||
if not utterance:
|
||||
continue
|
||||
@@ -1016,8 +1007,6 @@ class VoiceDaemon:
|
||||
engines.audio.flush() # clear any TTS echo captured while speaking
|
||||
except Exception:
|
||||
pass
|
||||
if self.follow_up_window > 0:
|
||||
self._follow_until = time.time() + self.follow_up_window
|
||||
try:
|
||||
engines.wake.reset()
|
||||
except Exception:
|
||||
|
||||
@@ -96,7 +96,6 @@ def make_daemon(frames, stt_text="hello", config=None):
|
||||
cfg = {
|
||||
"audio": {"frame_ms": 80, "sample_rate": 16000},
|
||||
"vad": {"silence_ms": 160, "min_speech_ms": 80, "max_utterance_s": 30},
|
||||
"follow_up_window_s": 5.0,
|
||||
"max_speak_chars": 600,
|
||||
}
|
||||
if config:
|
||||
@@ -311,16 +310,17 @@ def test_speak_synthesizes_and_plays():
|
||||
daemon.speak(" hello there ")
|
||||
assert engines.tts.spoken == ["hello there"]
|
||||
assert engines.audio.writes == [(b"PCM", 22050)]
|
||||
# A reply opens the follow-up window (no wake word needed next).
|
||||
assert daemon._follow_until > 0
|
||||
|
||||
|
||||
def test_follow_up_window_accepts_without_wake():
|
||||
def test_no_follow_up_after_reply():
|
||||
# The wake word is required for every command: speech after a reply is not
|
||||
# captured until the wake word fires again.
|
||||
daemon, engines = make_daemon([b"speech", b"SIL", b"SIL"])
|
||||
daemon.speak("are you there?") # opens the follow-up window
|
||||
daemon.speak("are you there?")
|
||||
heard = []
|
||||
daemon.run(heard.append)
|
||||
assert heard == ["hello"]
|
||||
assert heard == []
|
||||
assert engines.stt.calls == []
|
||||
|
||||
|
||||
def test_speak_truncates_long_text():
|
||||
|
||||
Reference in new issue
Block a user