From 9dcbb891500ed5bf6a432e6face8c15482f5c803 Mon Sep 17 00:00:00 2001 From: sayam93 <163408168+sayam93@users.noreply.github.com> Date: Fri, 15 Nov 2024 21:20:18 +0530 Subject: [PATCH] Enhancement: LED Functionality Enhances the existing LED functionality and increased the pong timeout interval --- examples/2mic_service.py | 30 ++++++++++++++++++++++++++++-- wyoming_satellite/satellite.py | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/examples/2mic_service.py b/examples/2mic_service.py index 0b44e62..4b71ea5 100644 --- a/examples/2mic_service.py +++ b/examples/2mic_service.py @@ -13,6 +13,7 @@ from wyoming.asr import Transcript from wyoming.event import Event from wyoming.satellite import ( + PauseSatellite, RunSatellite, SatelliteConnected, SatelliteDisconnected, @@ -22,6 +23,10 @@ from wyoming.server import AsyncEventHandler, AsyncServer from wyoming.vad import VoiceStarted from wyoming.wake import Detection +from wyoming.tts import Synthesize +from wyoming.audio import AudioStop +from wyoming.snd import Played +from wyoming.error import Error _LOGGER = logging.getLogger() @@ -79,9 +84,12 @@ async def main() -> None: _BLACK = (0, 0, 0) _WHITE = (255, 255, 255) _RED = (255, 0, 0) +_DARK_RED = (50, 0, 0) _YELLOW = (255, 255, 0) _BLUE = (0, 0, 255) _GREEN = (0, 255, 0) +_CYAN = (0, 255, 255) +_PURPLE = (128, 0, 128) class LEDsEventHandler(AsyncEventHandler): @@ -99,6 +107,7 @@ def __init__( self.cli_args = cli_args self.client_id = str(time.monotonic_ns()) self.leds = leds + self.previous_event = None _LOGGER.debug("Client connected: %s", self.client_id) @@ -119,6 +128,8 @@ async def handle_event(self, event: Event) -> bool: self.color(_BLACK) elif RunSatellite.is_type(event.type): self.color(_BLACK) + elif SatelliteDisconnected.is_type(event.type): + self.color(_DARK_RED) elif SatelliteConnected.is_type(event.type): # Flash for _ in range(3): @@ -126,8 +137,23 @@ async def handle_event(self, event: Event) -> bool: await asyncio.sleep(0.3) self.color(_BLACK) await asyncio.sleep(0.3) - elif SatelliteDisconnected.is_type(event.type): - self.color(_RED) + elif PauseSatellite.is_type(event.type): + self.color(_DARK_RED) + elif Error.is_type(event.type): + # Flash + for _ in range(3): + self.color(_PURPLE) + await asyncio.sleep(0.3) + self.color(_BLACK) + await asyncio.sleep(0.3) + # While the assist is responding with audio, the LEDs should be cyan + elif Synthesize.is_type(event.type): + self.color(_CYAN) + # When the assist is done responding with audio, the LEDs should be black + elif Played.is_type(event.type) and AudioStop.is_type(self.previous_event): + self.color(_BLACK) + + self.previous_event = event.type return True diff --git a/wyoming_satellite/satellite.py b/wyoming_satellite/satellite.py index 7a1dd58..f1a8979 100644 --- a/wyoming_satellite/satellite.py +++ b/wyoming_satellite/satellite.py @@ -47,7 +47,7 @@ _LOGGER = logging.getLogger() -_PONG_TIMEOUT: Final = 5 +_PONG_TIMEOUT: Final = 15 _PING_SEND_DELAY: Final = 2 _WAKE_INFO_TIMEOUT: Final = 2