Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ dmypy.json
.cache/

# Project specific
memory.json
memory.json

# Ignore audio recording files
.wav
39 changes: 29 additions & 10 deletions agent-memory/utils/record_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down