From 73b6793c0289de4c9d4d70e10a895255c8e7b322 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Apr 2026 16:47:27 -0500 Subject: [PATCH] Enable Edge TPU for YAMNet sound classification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer yamnet_edgetpu.tflite when available, fall back to CPU model. ~50-100ms → ~2-3ms inference per classification. Co-Authored-By: Claude Opus 4.6 (1M context) --- headmic.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/headmic.py b/headmic.py index b41896c..87e01f6 100644 --- a/headmic.py +++ b/headmic.py @@ -465,15 +465,19 @@ async def startup(): # --- Sound classifier (optional) --- model_dir = Path(__file__).parent / "models" + edgetpu_model_path = model_dir / "yamnet_edgetpu.tflite" model_path = model_dir / "yamnet.tflite" class_map_path = model_dir / "yamnet_class_map.csv" - if model_path.exists() and class_map_path.exists(): + # Prefer Edge TPU model if available + use_edgetpu = edgetpu_model_path.exists() + active_model = edgetpu_model_path if use_edgetpu else model_path + if active_model.exists() and class_map_path.exists(): try: from sound_id import SoundClassifier - sound_classifier = SoundClassifier(str(model_path), str(class_map_path)) + sound_classifier = SoundClassifier(str(active_model), str(class_map_path), use_edgetpu=use_edgetpu) sound_ring_buffer = collections.deque(maxlen=31) state.sound_classification_enabled = True - logger.info("Sound classification enabled (YAMNet)") + logger.info("Sound classification enabled (YAMNet %s)", "Edge TPU" if use_edgetpu else "CPU") sc_thread = threading.Thread(target=sound_classifier_loop, daemon=True) sc_thread.start()