From 89f3e3174f108d2d4e40184267495c8236632250 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Fri, 8 Dec 2023 11:29:10 -0600 Subject: [PATCH] Add --detect-command --- README.md | 2 ++ wyoming_satellite/__main__.py | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07c6f5e..afd5c63 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ You can also use `--mic-volume-multiplier X` to multiply all audio samples by `X Satellites can respond to events from the server by running commands: +* `--detect-command` - wake word detection has started, but not detected yet (no stdin) * `--streaming-start-command` - audio has started streaming to server * `--detection-command` - wake word is detected (wake word name on stdin) * `--transcript-command` - speech-to-text transcript is returned (text on stdin) @@ -138,5 +139,6 @@ Satellites can respond to events from the server by running commands: * `--synthesize-command` - text-to-speech text is returned (text on stdin) * `--tts-start-command` - text-to-speech response started (no stdin) * `--tts-stop-command` - text-to-speech response stopped (no stdin) +* `--error-command` - an error was sent from the server (text on stdin) For more advanced scenarios, use an event service (`--event-uri`). See `wyoming_satellite/example_event_client.py` for a basic client that just logs events. diff --git a/wyoming_satellite/__main__.py b/wyoming_satellite/__main__.py index 7b4f937..8939e50 100644 --- a/wyoming_satellite/__main__.py +++ b/wyoming_satellite/__main__.py @@ -145,6 +145,9 @@ async def main() -> None: parser.add_argument( "--event-uri", help="URI of Wyoming service to forward events to" ) + parser.add_argument( + "--detect-command", help="Command to run when wake word detection starts" + ) parser.add_argument( "--detection-command", help="Command to run when wake word is detected" ) @@ -176,6 +179,10 @@ async def main() -> None: "--streaming-start-command", help="Command to run when audio streaming starts", ) + parser.add_argument( + "--error-command", + help="Command to run when an error occurs", + ) # Sounds parser.add_argument( @@ -199,6 +206,10 @@ async def main() -> None: "--zeroconf-name", help="Name used for zeroconf discovery (default: MAC from uuid.getnode)", ) + parser.add_argument( + "--zeroconf-host", + help="Host address for zeroconf discovery (default: detect)", + ) # parser.add_argument("--debug", action="store_true", help="Log DEBUG messages") args = parser.parse_args() @@ -261,9 +272,13 @@ async def main() -> None: await register_server( name=args.zeroconf_name, port=tcp_server.port, - host=tcp_server.host, + host=args.zeroconf_host, + ) + _LOGGER.debug( + "Zeroconf discovery enabled (name=%s, host=%s)", + args.zeroconf_name, + args.zeroconf_host, ) - _LOGGER.debug("Zeroconf discovery enabled (name=%s)", args.zeroconf_name) try: await server.run(partial(SatelliteEventHandler, wyoming_info, args)) @@ -699,7 +714,10 @@ class SatelliteEventHandler(AsyncEventHandler): async def _forward_event(self, event: Event) -> None: """Forward a Wyoming event to a client and run event commands.""" - if self.cli_args.detection_command and Detection.is_type(event.type): + if self.cli_args.detect_command and Detect.is_type(event.type): + # Wake word detection started + await self._run_event_command(self.cli_args.detect_command) + elif self.cli_args.detection_command and Detection.is_type(event.type): # Wake word is detected detection = Detection.from_event(event) await self._run_event_command( @@ -729,6 +747,10 @@ class SatelliteEventHandler(AsyncEventHandler): elif self.cli_args.tts_stop_command and AudioStop.is_type(event.type): # TTS audio stop await self._run_event_command(self.cli_args.tts_stop_command) + elif self.cli_args.error_command and Error.is_type(event.type): + # Error occurred + error = Error.from_event(event) + await self._run_event_command(self.cli_args.error_command, error.text) if not self.cli_args.event_uri: # No external service