From 1f0ee10efefa6c06629e0e534fc974b2e2bc57cf Mon Sep 17 00:00:00 2001 From: dscripka Date: Sat, 28 Jan 2023 13:58:57 -0500 Subject: [PATCH] Adjusted some example scripts to fix bugs and removed 'plotext' usage as it wasn't functioning right on low-power hardware --- examples/README.md | 2 +- examples/capture_activations.py | 4 ++++ examples/detect_from_microphone.py | 32 +++++++++++++++++++----------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/README.md b/examples/README.md index 0d6e168..e100c6f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,7 +6,7 @@ Included are several example scripts demonstrating the usage of openWakeWord. So This is a simple example which allows you to test openWakeWord by using a locally connected microphone. To run the script, follow these steps: -1) Install the example-specific requirements: `pip install plotext pyaudio` +1) Install the example-specific requirements: `pip install pyaudio` 2) Run the script: `python detect_from_microphone.py`. diff --git a/examples/capture_activations.py b/examples/capture_activations.py index f44855c..59f0339 100644 --- a/examples/capture_activations.py +++ b/examples/capture_activations.py @@ -88,6 +88,10 @@ save_delay = 1 # seconds # Set cooldown period before another clip can be saved cooldown = 4 # seconds +# Create output directory if it does not already exist +if not os.path.exists(args.output_dir): + os.mkdir(args.output_dir) + # Run capture loop, checking for hotwords if __name__ == "__main__": # Predict continuously on audio stream diff --git a/examples/detect_from_microphone.py b/examples/detect_from_microphone.py index 740e063..7390bfb 100644 --- a/examples/detect_from_microphone.py +++ b/examples/detect_from_microphone.py @@ -13,7 +13,6 @@ # limitations under the License. # Imports -import plotext as plt import pyaudio import numpy as np from openwakeword.model import Model @@ -32,6 +31,12 @@ owwModel = Model() # Run capture loop, checking for hotwords if __name__ == "__main__": # Predict continuously on audio stream + print("\n\n") + print("#"*100) + print("Listening for wakewords...") + print("#"*100) + print("\n"*13) + while True: # Get audio audio = np.frombuffer(mic_stream.read(CHUNK), dtype=np.int16) @@ -39,18 +44,21 @@ if __name__ == "__main__": # Feed to openWakeWord model prediction = owwModel.predict(audio) - # Get predictions from prediction buffers and plot - plt.cld() - plt.clt() + # Generate output string header + n_spaces = 16 + output_string_header = """ + Model Name | Score | Wakeword Status + -------------------------------------- + """ + for mdl in owwModel.prediction_buffer.keys(): - # Plot scores in graph + # Add scores in formatted table scores = list(owwModel.prediction_buffer[mdl]) - plt.plot(scores) + curr_score = format(scores[-1], '.20f').replace("-", "") - # Plot text showing name of model with scores >= 0.5 (default threshold) - if max(scores) >= 0.5: - plt.text(mdl, 15, 0.9, alignment="center", color = "blue", style="bold") + output_string_header += f"""{mdl}{" "*(n_spaces - len(mdl))} | {curr_score[0:5]} | {"--"+" "*20 if scores[-1] <= 0.5 else "Wakeword Detected!"} + """ - plt.ylim(0,1) - plt.show() - plt.sleep(0.005) + # Print results table + print("\033[F"*14) + print(output_string_header, " ", end='\r')