From 400d42c71e797e3584ecc52bc38a01eb68994e5b Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 12 Apr 2024 13:32:58 -0700 Subject: [PATCH] Update default config and documentation Read HANA server address from config Read Node username/password from config --- README.md | 16 ++++++++++++++++ neon_nodes/configuration/system.yaml | 4 ++++ neon_nodes/voice_client.py | 15 ++++++++++----- neon_nodes/websocket_client.py | 15 ++++++++------- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index de32b82..697de17 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,19 @@ processing, and presenting a response to the user. The voice client will start a service that listens for a wake word on the local system, sends recorded speech to a HANA endpoint for processing, and plays back the response. + +## Websocket Client +The websocket client starts a local listener service and establishes a websocket +connection to a remove HANA server. Compared to the Voice Client, this has +lower latency and allows for asynchronous messages from the HANA server. + +## Configuration +This service is configured via `~/.config/neon/neon.yaml`. + +```yaml +neon_node: + description: Neon Node # Friendly description of the node + hana_address: https://hana.neonaiservices.com # Hana server HTTP address + hana_username: node_user # Hana node user username + hana_password: node_password # Hana node user password +``` diff --git a/neon_nodes/configuration/system.yaml b/neon_nodes/configuration/system.yaml index ee4bf1d..4818fd0 100644 --- a/neon_nodes/configuration/system.yaml +++ b/neon_nodes/configuration/system.yaml @@ -1,5 +1,9 @@ neon_node: description: Neon Node +# hana_address: https://hana.neonaiservices.com + hana_address: http://10.0.30.10:8080 + hana_username: node_user + hana_password: node_password microphone: module: ovos-microphone-plugin-alsa listener: diff --git a/neon_nodes/voice_client.py b/neon_nodes/voice_client.py index 16c46dc..981f2d4 100644 --- a/neon_nodes/voice_client.py +++ b/neon_nodes/voice_client.py @@ -58,7 +58,9 @@ def __init__(self, bus=None, ready_hook=on_ready, error_hook=on_error, self.stopping_hook = stopping_hook alive_hook() self.config = Configuration() - self._device_data = self.config.get('neon_node', {}) + self._node_config = self.config.get('neon_node', {}) + self._hana_address = self._node_config.get('hana_address') + LOG.init(self.config.get("logging")) self.bus = bus or FakeBus() self.lang = self.config.get('lang') or "en-us" @@ -85,7 +87,7 @@ def __init__(self, bus=None, ready_hook=on_ready, error_hook=on_error, self._error_sound = None self._network_info = dict() - self._node_data = dict() + self._node_data = {"description": self._node_config.get("description")} started_hook() self.run() @@ -217,18 +219,21 @@ def get_audio_response(self, audio: bytes): audio_data = b64encode(audio).decode("utf-8") transcript = request_backend("neon/get_stt", {"encoded_audio": audio_data, - "lang_code": self.lang}) + "lang_code": self.lang}, + server_url=self._hana_address) transcribed = transcript['transcripts'][0] LOG.info(transcribed) response = request_backend("neon/get_response", {"lang_code": self.lang, "user_profile": self.user_profile, "node_data": self.node_data, - "utterance": transcribed}) + "utterance": transcribed}, + server_url=self._hana_address) answer = response['answer'] LOG.info(answer) audio = request_backend("neon/get_tts", {"lang_code": self.lang, - "to_speak": answer}) + "to_speak": answer}, + server_url=self._hana_address) audio_bytes = b64decode(audio['encoded_audio']) play(AudioSegment.from_file(io.BytesIO(audio_bytes), format="wav")) LOG.info(f"Playback completed") diff --git a/neon_nodes/websocket_client.py b/neon_nodes/websocket_client.py index 09708cf..e1686f3 100644 --- a/neon_nodes/websocket_client.py +++ b/neon_nodes/websocket_client.py @@ -59,12 +59,13 @@ def __init__(self, bus=None, ready_hook=on_ready, error_hook=on_error, self.stopping_hook = stopping_hook alive_hook() self.config = Configuration() - + node_config = self.config["neon_node"] + server_addr = node_config["hana_address"] self._connected = Event() - # TODO: Endpoint and credentials from config - auth_data = requests.post("http://0.0.0.0:8080/auth/login", - json={"username": "node_user", - "password": "node_password"}).json() + + auth_data = requests.post(f"{server_addr}/auth/login", json={ + "username": node_config["hana_username"], + "password": node_config["hana_password"]}).json() LOG.info(auth_data) def on_connect(*_, **__): @@ -73,8 +74,8 @@ def on_connect(*_, **__): def on_error(_, exception): self.error_hook() raise ConnectionError(f"Failed to connect: {exception}") - - self.websocket = WebSocketApp(f"ws://0.0.0.0:8080/node/v1?token={auth_data['access_token']}", + ws_address = server_addr.replace("http", "ws", 1) + self.websocket = WebSocketApp(f"{ws_address}/node/v1?token={auth_data['access_token']}", on_message=self._on_ws_data, on_open=on_connect, on_error=on_error)