Skip to content

Commit

Permalink
src: Add test recording program.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Nov 14, 2023
1 parent 11e3b4c commit 33ae53b
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/test_record.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 33ae53b

Please sign in to comment.