From 33ae53bf03bac3dbd226d71aec5a193a20259298 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 14 Nov 2023 12:40:26 +1100 Subject: [PATCH] src: Add test recording program. Signed-off-by: Damien George --- src/test_record.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test_record.py diff --git a/src/test_record.py b/src/test_record.py new file mode 100644 index 0000000..656ef28 --- /dev/null +++ b/src/test_record.py @@ -0,0 +1,57 @@ +from microbit import * + +mouth_open = Image( + "09090:" + "00000:" + "09990:" + "90009:" + "09990" +) +mouth_closed = Image( + "09090:" + "00000:" + "00000:" + "99999:" + "00000" +) +play = Image( + "00000:" + "04740:" + "07970:" + "04740:" + "00000" +) + +RECORDING_RATE = 7812 +RECORDING_SECONDS = 5 +RECORDING_SIZE = RECORDING_RATE * RECORDING_SECONDS + +my_recording = audio.AudioFrame(RECORDING_SIZE) + +while True: + if button_a.is_pressed(): + microphone.record_into(my_recording, rate=RECORDING_RATE, wait=False) + display.show([mouth_open, mouth_closed], loop=True, wait=False, delay=150) + while button_a.is_pressed() and microphone.is_recording(): + sleep(50) + microphone.stop_recording() + display.show(mouth_closed) + while button_a.is_pressed(): + sleep(50) + display.clear() + my_recording *= 5 + if button_b.is_pressed(): + audio.play(my_recording, wait=False) + level = 0 + while audio.is_playing(): + l = audio.sound_level() + if l > level: + level = l + else: + level *= 0.95 + display.show(play * min(1, level / 100)) + x = accelerometer.get_x() + audio.set_rate(max(2250, scale(x, (-1000, 1000), (2250, 13374)))) + sleep(5) + display.clear() + sleep(100)