Keep audio loop running when Porcupine key is missing
Without this fix, listener_loop exits early on Porcupine init failure, which starves the sound classifier ring buffer. Now the audio loop continues for YAMNet classification even without wake word detection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
13
headmic.py
13
headmic.py
@@ -234,6 +234,7 @@ def listener_loop():
|
||||
global state, dual_stream
|
||||
|
||||
logger.info("Initializing Porcupine...")
|
||||
porcupine = None
|
||||
try:
|
||||
porcupine = pvporcupine.create(
|
||||
access_key=PORCUPINE_ACCESS_KEY,
|
||||
@@ -241,8 +242,7 @@ def listener_loop():
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to init Porcupine: {e}")
|
||||
state.error = str(e)
|
||||
return
|
||||
logger.warning("Wake word detection disabled — audio loop continues for classification")
|
||||
|
||||
vad = webrtcvad.Vad(VAD_AGGRESSIVENESS)
|
||||
|
||||
@@ -264,9 +264,6 @@ def listener_loop():
|
||||
|
||||
state.active_side = side
|
||||
|
||||
# Convert bytes to int16 array for Porcupine
|
||||
pcm = struct.unpack_from("h" * 512, frame_data)
|
||||
|
||||
# Feed sound classifier ring buffer
|
||||
if sound_ring_buffer is not None:
|
||||
sound_ring_buffer.append(frame_data)
|
||||
@@ -275,7 +272,10 @@ def listener_loop():
|
||||
if enrollment_buffer is not None:
|
||||
enrollment_buffer.append(frame_data)
|
||||
|
||||
# Check for wake word
|
||||
# Check for wake word (skip if Porcupine not available)
|
||||
keyword_index = -1
|
||||
if porcupine:
|
||||
pcm = struct.unpack_from("h" * 512, frame_data)
|
||||
keyword_index = porcupine.process(pcm)
|
||||
|
||||
if keyword_index >= 0 and not is_recording:
|
||||
@@ -345,6 +345,7 @@ def listener_loop():
|
||||
logger.error(f"Listener error: {e}")
|
||||
state.error = str(e)
|
||||
finally:
|
||||
if porcupine:
|
||||
porcupine.delete()
|
||||
state.listening = False
|
||||
leds_off()
|
||||
|
||||
Reference in New Issue
Block a user