new alarm mechanism

This commit is contained in:
Mikkeli Matlock
2026-02-15 22:44:36 +09:00
parent df9cc6bd09
commit d9c5066c29
9 changed files with 241 additions and 21 deletions

View File

@@ -12,8 +12,19 @@ CHUNK_SIZE = 4096
AUDIO_DIR = Path(__file__).parent / "assets" / "alarm"
def find_wav() -> Path:
"""Find the first .wav file in the alarm assets directory."""
def find_wav(path: Path | None = None) -> Path:
"""Return a WAV file path.
If *path* is given and points to an existing file, use it directly.
Otherwise fall back to the first .wav found in the alarm assets directory.
"""
if path is not None:
p = Path(path)
if p.is_file():
log.info("Using audio file: %s", p)
return p
log.warning("Specified audio path not found: %s — falling back to glob", p)
wavs = list(AUDIO_DIR.glob("*.wav"))
if not wavs:
raise FileNotFoundError(f"No .wav files found in {AUDIO_DIR}")