From 58ec0943806b5907b2a3218eb0935b1cdf1c92b3 Mon Sep 17 00:00:00 2001 From: David Scripka Date: Thu, 9 Nov 2023 08:36:43 -0500 Subject: [PATCH] Added table for detections and styling to websocket example --- examples/web/streaming_client.html | 216 ++++++++++++++++++++--------- examples/web/streaming_server.py | 6 +- 2 files changed, 155 insertions(+), 67 deletions(-) diff --git a/examples/web/streaming_client.html b/examples/web/streaming_client.html index 3bf5005..44c98d8 100644 --- a/examples/web/streaming_client.html +++ b/examples/web/streaming_client.html @@ -1,31 +1,127 @@ - Websocket Microphone Streaming +

Streaming Audio to openWakeWord Using Websockets

- + + + + + + + + + + + +
WakewordDetected
\ No newline at end of file diff --git a/examples/web/streaming_server.py b/examples/web/streaming_server.py index c386bbe..449d251 100644 --- a/examples/web/streaming_server.py +++ b/examples/web/streaming_server.py @@ -26,12 +26,16 @@ import numpy as np from openwakeword import Model import resampy import argparse +import json # Define websocket handler async def websocket_handler(request): ws = web.WebSocketResponse() await ws.prepare(request) + # Send loaded models + await ws.send_str(json.dumps({"loaded_models": list(owwModel.models.keys())})) + # Start listening for websocket messages async for msg in ws: # Get the sample rate of the microphone from the browser @@ -61,7 +65,7 @@ async def websocket_handler(request): activations.append(key) if activations != []: - await ws.send_str(str(activations)) + await ws.send_str(json.dumps({"activations": activations})) return ws