-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_disabled.py
More file actions
51 lines (43 loc) · 2.1 KB
/
Copy pathstate_disabled.py
File metadata and controls
51 lines (43 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Atlas Voice state: disabled — models unloaded, GPU free."""
from logging_utils import log_debug, log_info, log_error
from mailbox import Mailbox
from context import handle_quit
def state_disabled(ctx):
"""Disabled state. Models unloaded, GPU free. Wait for TOGGLE_ENABLE.
PRE: Models are unloaded, GPU is free.
POST: On enable: loads models, starts audio buffer.
RETURNS: "listening" (enable success), None (quit).
INTERRUPTS: Mailbox TOGGLE_ENABLE, QUIT via blocking wait; TOGGLE_PAUSE ignored.
"""
log_info("[STATE] Entering: disabled")
ctx.set_icon("AV_DISABLE")
log_info("Atlas disabled (GPU released). Use tray menu to enable.")
while True:
req = ctx.mailbox.wait(timeout=0.5)
if req == Mailbox.TOGGLE_ENABLE:
log_info("[STATE] Enabling (loading models)...")
try:
# Check device presence before loading models to avoid
# wasting GPU memory if the device is unavailable
if ctx.audio_buffer.device_name and not ctx.audio_buffer.is_device_present():
log_error(f"[STATE] Audio device '{ctx.audio_buffer.device_name}' not found, staying disabled")
continue
ctx.load_models()
# Start audio stream if not running
try:
ctx.audio_buffer.start()
except Exception as e:
log_error(f"[STATE] Audio start failed after model load: {e}")
# Unload models to free GPU since we can't proceed
ctx.unload_models()
continue
log_info("[STATE] Exiting: disabled -> listening")
return "listening"
except Exception as e:
log_error(f"[STATE] Model load failed, staying disabled: {e}")
continue
elif req == Mailbox.TOGGLE_PAUSE:
log_debug("[TRAP] In DISABLED, got TOGGLE_PAUSE (nonsensical, ignored)")
elif req == Mailbox.QUIT:
log_info("[STATE] Exiting: disabled -> shutdown")
return handle_quit(ctx)