Configure demo_audio_loopback.py to record for a fixed 10-second duration to eliminate button-release checking from loop
This commit is contained in:
+14
-15
@@ -79,14 +79,14 @@ def main():
|
||||
if board_config.BOARD_TYPE == 'WAVESHARE_RLCD':
|
||||
display.text("RLCD Audio Loopback Test", 10, 10, 1)
|
||||
display.line(10, 20, 390, 20, 1)
|
||||
display.text("1. Press & HOLD KEY button to record", 15, 60, 1)
|
||||
display.text("2. Release key to play back", 15, 80, 1)
|
||||
display.text("1. Press KEY button to record 10s", 15, 60, 1)
|
||||
display.text("2. Playback will start automatically", 15, 80, 1)
|
||||
display.text("Ready...", 15, 120, 1)
|
||||
else:
|
||||
display.text("Touch Audio Loopback Test", 10, 10, 1)
|
||||
display.line(10, 20, 310, 20, 1)
|
||||
display.text("1. Press & HOLD screen/KEY to record", 10, 50, 1)
|
||||
display.text("2. Release to play back", 10, 70, 1)
|
||||
display.text("1. Press screen/KEY to record 10s", 10, 50, 1)
|
||||
display.text("2. Playback starts automatically", 10, 70, 1)
|
||||
display.text("Ready...", 10, 100, 1)
|
||||
display.show()
|
||||
|
||||
@@ -120,13 +120,13 @@ def main():
|
||||
if board_config.BOARD_TYPE == 'WAVESHARE_RLCD':
|
||||
display.text("RLCD Audio Loopback Test", 10, 10, 1)
|
||||
display.line(10, 20, 390, 20, 1)
|
||||
display.text("RECORDING NOW!", 15, 80, 1)
|
||||
display.text("Keep holding key...", 15, 100, 1)
|
||||
display.text("RECORDING: 10 seconds...", 15, 80, 1)
|
||||
display.text("Speak into microphone!", 15, 100, 1)
|
||||
else:
|
||||
display.text("Touch Audio Loopback Test", 10, 10, 1)
|
||||
display.line(10, 20, 310, 20, 1)
|
||||
display.text("RECORDING NOW!", 10, 60, 1)
|
||||
display.text("Keep holding trigger...", 10, 80, 1)
|
||||
display.text("RECORDING: 10 seconds...", 10, 60, 1)
|
||||
display.text("Speak now!", 10, 80, 1)
|
||||
display.show()
|
||||
|
||||
# We record as long as the button is pressed (or up to 10 seconds max)
|
||||
@@ -168,14 +168,13 @@ def main():
|
||||
pass
|
||||
|
||||
# Record loop
|
||||
buffer = bytearray(2048)
|
||||
buffer = bytearray(1024)
|
||||
total_bytes = 0
|
||||
start_time = time.ticks_ms()
|
||||
max_duration_ms = 10000 # 10 seconds limit
|
||||
start_rec_time = time.time()
|
||||
|
||||
try:
|
||||
with open(filename, 'wb') as f:
|
||||
while is_talk_trigger_active() and time.ticks_diff(time.ticks_ms(), start_time) < max_duration_ms:
|
||||
while (time.time() - start_rec_time) < 10:
|
||||
bytes_read = i2s_rx.readinto(buffer)
|
||||
if bytes_read > 0:
|
||||
f.write(buffer[:bytes_read])
|
||||
@@ -187,10 +186,10 @@ def main():
|
||||
if mclk_pwm:
|
||||
mclk_pwm.deinit()
|
||||
|
||||
print(f"Trigger released! Recorded {total_bytes} bytes to '{filename}'.")
|
||||
print(f"Recorded {total_bytes} bytes to '{filename}'.")
|
||||
|
||||
# Debounce release
|
||||
time.sleep_ms(150)
|
||||
# Wait for release of key/trigger to debounce
|
||||
time.sleep_ms(200)
|
||||
|
||||
# 4. Playback
|
||||
if display:
|
||||
|
||||
Reference in New Issue
Block a user