diff --git a/.gitignore b/.gitignore index 8e5d99e..e5a96fb 100644 --- a/.gitignore +++ b/.gitignore @@ -81,4 +81,7 @@ dmypy.json .cache/ # Project specific -memory.json \ No newline at end of file +memory.json + +# Ignore audio recording files +.wav \ No newline at end of file diff --git a/agent-memory/utils/record_audio.py b/agent-memory/utils/record_audio.py index 0079afa..34bd3e8 100644 --- a/agent-memory/utils/record_audio.py +++ b/agent-memory/utils/record_audio.py @@ -4,7 +4,28 @@ from datetime import datetime from typing import Optional import sys -import select +import os # Import os module +# No longer directly importing select as it will be conditionally imported + +def wait_for_enter(): + """Waits for the Enter key to be pressed in a cross-platform way.""" + if os.name == 'nt': # Windows + import msvcrt + while True: + # Check if a key has been pressed and if it's the Enter key (ASCII 13) + if msvcrt.kbhit(): + key = msvcrt.getch() + if key == b'\r' or key == b'\n': # Check for both carriage return and newline + break + time.sleep(0.1) # Reduce CPU usage + else: # Unix-like (Linux, macOS) + import select + while True: + # Check if Enter key was pressed + if select.select([sys.stdin], [], [], 0.1)[0]: + sys.stdin.readline() + break + time.sleep(0.1) # Reduce CPU usage def record_audio() -> Optional[str]: """Records audio from microphone when user presses Enter and stops when Enter is pressed again. @@ -40,15 +61,13 @@ def callback(in_data, frame_count, time_info, status): print("Press Enter to start recording, press Enter again to stop...") while True: - # Check if Enter key was pressed - if select.select([sys.stdin], [], [], 0.1)[0]: - sys.stdin.readline() - if not recording: - recording = True - print("Recording...") - else: - break - time.sleep(0.1) # Reduce CPU usage + # Call the cross-platform wait_for_enter function + wait_for_enter() + if not recording: + recording = True + print("Recording...") + else: + break stream.stop_stream() stream.close()