Skip to content

Commit

Permalink
Fixes to detect websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Jul 12, 2023
1 parent 8d24270 commit 2154fdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 67 deletions.
8 changes: 5 additions & 3 deletions programs/wake/home_assistant/bin/detect_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def main() -> None:
_LOGGER.debug("Starting detection")
message_id = 1
detect_args = {
"type": "wake/detect",
"type": "wake_word/detect",
"id": message_id,
}
if args.entity_id:
Expand All @@ -99,7 +99,9 @@ async def main() -> None:

# Get handler id.
# This is a single byte prefix that needs to be in every binary payload.
handler_id = bytes([msg["result"]["handler_id"]])
msg = await websocket.receive_json()
_LOGGER.debug(msg)
handler_id = bytes([msg["event"]["handler_id"]])

# Detect wakeword(s)
_LOGGER.debug("Starting detection")
Expand Down Expand Up @@ -135,7 +137,7 @@ async def main() -> None:
_LOGGER.info(result_json)
write_event(
Detection(
name=result_json["ww_id"],
name=result_json["event"]["ww_id"],
timestamp=result_json.get("timestamp"),
).event()
)
Expand Down
67 changes: 3 additions & 64 deletions programs/wake/openwakeword-lite/bin/server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,6 @@
_DIR = Path(__file__).parent


# class StreamAudioHandler(socketserver.StreamRequestHandler):
# def __init__(self, state: State, *args, **kwargs):
# self._state = state
# super().__init__(*args, **kwargs)

# def handle(self):
# client_id = self.client_address
# _LOGGER.info("New client: %s", client_id)

# data = ClientData(self.wfile)
# for ww_name in self._state.wake_words:
# data.wake_words[ww_name] = WakeWordData()

# with self._state.clients_lock:
# self._state.clients[client_id] = data

# audio_bytes = bytes()

# with open("/tmp/test.raw", "wb") as f:
# try:
# while True:
# chunk_bytes = self.request.recv(_BYTES_PER_CHUNK)
# if not chunk_bytes:
# # Empty chunk when client disconnects
# break

# f.write(chunk_bytes)

# audio_bytes += chunk_bytes
# while len(audio_bytes) >= _BYTES_PER_CHUNK:
# # NOTE: Audio is *not* normalized
# chunk_array = np.frombuffer(
# audio_bytes[:_BYTES_PER_CHUNK], dtype=np.int16
# ).astype(np.float32)

# with self._state.audio_lock:
# # Shift samples left
# data.audio[: -len(chunk_array)] = data.audio[
# len(chunk_array) :
# ]

# # Add new samples to end
# data.audio[-len(chunk_array) :] = chunk_array
# data.new_audio_samples = min(
# len(data.audio),
# data.new_audio_samples + len(chunk_array),
# )

# self._state.audio_ready.release()
# audio_bytes = audio_bytes[_BYTES_PER_CHUNK:]
# except ConnectionResetError:
# _LOGGER.debug("Client disconnected: %s", client_id)
# except Exception:
# _LOGGER.exception("handle")
# finally:
# # Clean up
# with self._state.clients_lock:
# self._state.clients.pop(client_id, None)


# -----------------------------------------------------------------------------


async def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--uri", required=True, help="unix:// or tcp://")
Expand All @@ -102,18 +39,20 @@ async def main() -> None:
wake=[
WakeProgram(
name="openwakeword",
description="An open-source audio wake word (or phrase) detection framework with a focus on performance and simplicity.",
attribution=Attribution(
name="dscripka", url="https://github.com/dscripka/openWakeWord"
),
installed=True,
models=[
WakeModel(
name=model,
description=Path(model).stem,
attribution=Attribution(
name=model, url="https://github.com/dscripka/openWakeWord"
),
installed=True,
languages=["en"], # HACK
languages=[],
)
for model in args.model
],
Expand Down

0 comments on commit 2154fdc

Please sign in to comment.