Skip to content

Commit 33ae53b

Browse files
committed
src: Add test recording program.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 11e3b4c commit 33ae53b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/test_record.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from microbit import *
2+
3+
mouth_open = Image(
4+
"09090:"
5+
"00000:"
6+
"09990:"
7+
"90009:"
8+
"09990"
9+
)
10+
mouth_closed = Image(
11+
"09090:"
12+
"00000:"
13+
"00000:"
14+
"99999:"
15+
"00000"
16+
)
17+
play = Image(
18+
"00000:"
19+
"04740:"
20+
"07970:"
21+
"04740:"
22+
"00000"
23+
)
24+
25+
RECORDING_RATE = 7812
26+
RECORDING_SECONDS = 5
27+
RECORDING_SIZE = RECORDING_RATE * RECORDING_SECONDS
28+
29+
my_recording = audio.AudioFrame(RECORDING_SIZE)
30+
31+
while True:
32+
if button_a.is_pressed():
33+
microphone.record_into(my_recording, rate=RECORDING_RATE, wait=False)
34+
display.show([mouth_open, mouth_closed], loop=True, wait=False, delay=150)
35+
while button_a.is_pressed() and microphone.is_recording():
36+
sleep(50)
37+
microphone.stop_recording()
38+
display.show(mouth_closed)
39+
while button_a.is_pressed():
40+
sleep(50)
41+
display.clear()
42+
my_recording *= 5
43+
if button_b.is_pressed():
44+
audio.play(my_recording, wait=False)
45+
level = 0
46+
while audio.is_playing():
47+
l = audio.sound_level()
48+
if l > level:
49+
level = l
50+
else:
51+
level *= 0.95
52+
display.show(play * min(1, level / 100))
53+
x = accelerometer.get_x()
54+
audio.set_rate(max(2250, scale(x, (-1000, 1000), (2250, 13374))))
55+
sleep(5)
56+
display.clear()
57+
sleep(100)

0 commit comments

Comments
 (0)