Microphone Mute Button Bug

Bug fix to eliminate "pending" wake word detections while the mic was muted.
This commit is contained in:
imonlinux
2025-10-11 19:34:14 -07:00
committed by GitHub
parent aecf118983
commit 98c8585ae3
+11 -8
View File
@@ -12,7 +12,7 @@ from typing import Dict, List, Optional, Union
import numpy as np import numpy as np
import sounddevice as sd import sounddevice as sd
from .event_bus import EventBus, EventHandler, subscribe # ADDED EventHandler, subscribe from .event_bus import EventBus, EventHandler, subscribe
from .led_controller import LedController from .led_controller import LedController
from .microwakeword import MicroWakeWord, MicroWakeWordFeatures from .microwakeword import MicroWakeWord, MicroWakeWordFeatures
from .models import AvailableWakeWord, Preferences, ServerState, WakeWordType from .models import AvailableWakeWord, Preferences, ServerState, WakeWordType
@@ -35,7 +35,7 @@ else:
_LIB_DIR = _REPO_DIR / "lib" / "linux_amd64" _LIB_DIR = _REPO_DIR / "lib" / "linux_amd64"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# --- ADDED MIC MUTE HANDLER --- # --- MIC MUTE HANDLER ---
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
class MicMuteHandler(EventHandler): class MicMuteHandler(EventHandler):
@@ -49,6 +49,15 @@ class MicMuteHandler(EventHandler):
if is_muted: if is_muted:
self.state.event_bus.publish("mic_muted") self.state.event_bus.publish("mic_muted")
else: else:
# --- THIS IS THE FIX ---
# Clear the audio queue of stale data before unmuting
_LOGGER.debug("Clearing stale audio queue...")
while not self.state.audio_queue.empty():
try:
self.state.audio_queue.get_nowait()
except Queue.Empty:
break
# -------------------------
self.state.event_bus.publish("mic_unmuted") self.state.event_bus.publish("mic_unmuted")
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@@ -56,7 +65,6 @@ class MicMuteHandler(EventHandler):
async def main() -> None: async def main() -> None:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# ... (all parser arguments are the same) ...
parser.add_argument("--name", required=True) parser.add_argument("--name", required=True)
parser.add_argument( parser.add_argument(
"--audio-input-device", "--audio-input-device",
@@ -230,7 +238,6 @@ async def main() -> None:
clock_pin=args.led_clock_pin, clock_pin=args.led_clock_pin,
data_pin=args.led_data_pin, data_pin=args.led_data_pin,
) )
# --- ADDED: Instantiate Mic Mute Handler ---
mic_mute_handler = MicMuteHandler(state) mic_mute_handler = MicMuteHandler(state)
process_audio_thread = threading.Thread( process_audio_thread = threading.Thread(
@@ -275,7 +282,6 @@ async def main() -> None:
def process_audio(state: ServerState): def process_audio(state: ServerState):
"""Process audio chunks from the microphone.""" """Process audio chunks from the microphone."""
# ... (variable initializations are the same) ...
wake_words: List[Union[MicroWakeWord, OpenWakeWord]] = [] wake_words: List[Union[MicroWakeWord, OpenWakeWord]] = []
micro_features: Optional[MicroWakeWordFeatures] = None micro_features: Optional[MicroWakeWordFeatures] = None
micro_inputs: List[np.ndarray] = [] micro_inputs: List[np.ndarray] = []
@@ -286,14 +292,11 @@ def process_audio(state: ServerState):
try: try:
while True: while True:
# --- THIS IS THE CHANGE ---
# Check for mute status
if state.mic_muted: if state.mic_muted:
time.sleep(0.1) time.sleep(0.1)
continue continue
audio_chunk = state.audio_queue.get() audio_chunk = state.audio_queue.get()
# ... (rest of the function is the same) ...
if audio_chunk is None: if audio_chunk is None:
break break
if state.satellite is None: if state.satellite is None: