Skip to content

Commit

Permalink
Update default config and documentation
Browse files Browse the repository at this point in the history
Read HANA server address from config
Read Node username/password from config
  • Loading branch information
NeonDaniel committed Apr 12, 2024
1 parent 802c647 commit 400d42c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 4 additions & 0 deletions neon_nodes/configuration/system.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
15 changes: 10 additions & 5 deletions neon_nodes/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
15 changes: 8 additions & 7 deletions neon_nodes/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(*_, **__):
Expand All @@ -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)
Expand Down

0 comments on commit 400d42c

Please sign in to comment.