Skip to content

Commit

Permalink
Enhancement: LED Functionality
Browse files Browse the repository at this point in the history
Enhances the existing LED functionality and increased the pong timeout interval
  • Loading branch information
sayam93 committed Dec 15, 2024
1 parent a2bb7c8 commit 9dcbb89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 28 additions & 2 deletions examples/2mic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from wyoming.asr import Transcript
from wyoming.event import Event
from wyoming.satellite import (
PauseSatellite,
RunSatellite,
SatelliteConnected,
SatelliteDisconnected,
Expand All @@ -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()

Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand All @@ -119,15 +128,32 @@ 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):
self.color(_GREEN)
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

Expand Down
2 changes: 1 addition & 1 deletion wyoming_satellite/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9dcbb89

Please sign in to comment.