Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: LED Feedback #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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