From 86975c40267f00fd0d6cfda086b0ddc3f08bdf4d Mon Sep 17 00:00:00 2001 From: Shiven Mian Date: Tue, 13 Feb 2024 19:44:38 -0800 Subject: [PATCH] fix: added tom's fixes --- .gitignore | 1 + 01OS/01OS/clients/base_device.py | 15 ++++++++++++--- 01OS/01OS/clients/start.sh | 4 ++-- 01OS/start.sh | 7 +++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ff21f10..44773f4 100644 --- a/.gitignore +++ b/.gitignore @@ -167,3 +167,4 @@ cython_debug/ # ignore the aifs index files _.aifs +01OS/output_audio.wav \ No newline at end of file diff --git a/01OS/01OS/clients/base_device.py b/01OS/01OS/clients/base_device.py index f2197a4..1855253 100644 --- a/01OS/01OS/clients/base_device.py +++ b/01OS/01OS/clients/base_device.py @@ -50,7 +50,7 @@ send_queue = queue.Queue() class Device: def __init__(self): - pass + self.pressed_keys = set() def record_audio(self): @@ -125,12 +125,21 @@ class Device: RECORDING = False def on_press(self, key): - """Detect spacebar press.""" - if key == keyboard.Key.space: + """Detect spacebar press, ESC key press, and Ctrl+C combination.""" + self.pressed_keys.add(key) # Add the pressed key to the set + + if keyboard.Key.esc in self.pressed_keys: + logger.info("Exiting...") + os._exit(0) + elif keyboard.Key.space in self.pressed_keys: self.toggle_recording(True) + elif {keyboard.Key.ctrl, keyboard.KeyCode.from_char('c')} <= self.pressed_keys: + logger.info("Ctrl+C pressed. Exiting...") + os._exit(0) def on_release(self, key): """Detect spacebar release and ESC key press.""" + self.pressed_keys.discard(key) # Remove the released key from the key press tracking set if key == keyboard.Key.space: self.toggle_recording(False) elif key == keyboard.Key.esc or (key == keyboard.Key.ctrl and keyboard.Key.c): diff --git a/01OS/01OS/clients/start.sh b/01OS/01OS/clients/start.sh index 8e8edc9..844e6a0 100644 --- a/01OS/01OS/clients/start.sh +++ b/01OS/01OS/clients/start.sh @@ -1,8 +1,8 @@ DEVICE=$(uname -n) if [[ "$DEVICE" == "rpi" ]]; then cd 01OS - python -m 01OS.clients.rpi.device & + python -m 01OS.clients.rpi.device else cd 01OS - python -m 01OS.clients.macos.device & + python -m 01OS.clients.macos.device fi diff --git a/01OS/start.sh b/01OS/start.sh index 201f475..36b7ec6 100755 --- a/01OS/start.sh +++ b/01OS/start.sh @@ -1,5 +1,12 @@ #!/usr/bin/env bash +# Set python to prioritize the module files from the current directory +# If we don't do this, then the python interpreter will not be able to find the modules, +# and will throw an error like "ModuleNotFoundError: No module named '01OS'". +# If we solve the problem by pip installing the official 01OS package, then those +# modules will run instead of the local ones that we are trying to develop with. +export PYTHONPATH="$(pwd):$PYTHONPATH" + ### Import Environment Variables from .env SCRIPT_DIR="$(dirname "$0")" if [ ! -f "$SCRIPT_DIR/.env" ]; then