|
22 | 22 | "00000" |
23 | 23 | ) |
24 | 24 |
|
25 | | -my_recording = audio.AudioFrame(5000) |
| 25 | +my_recording = audio.AudioRecording(duration=5000) |
26 | 26 |
|
27 | 27 | while True: |
28 | 28 | if button_a.is_pressed(): |
29 | | - microphone.record_into(my_recording, wait=False) |
| 29 | + my_track = microphone.record_into(my_recording, wait=False) |
30 | 30 | display.show([mouth_open, mouth_closed], loop=True, wait=False, delay=150) |
31 | 31 | while button_a.is_pressed() and microphone.is_recording(): |
32 | 32 | sleep(50) |
|
35 | 35 | while button_a.is_pressed(): |
36 | 36 | sleep(50) |
37 | 37 | display.clear() |
38 | | - my_recording *= 2 # amplify volume |
| 38 | + # amplify volume |
| 39 | + GAIN = 2 |
| 40 | + #my_recording *= GAIN |
| 41 | + for i in range(len(my_track)): |
| 42 | + my_track[i] = max(0, min(128 + GAIN * (my_track[i] - 128), 255)) |
39 | 43 | if button_b.is_pressed(): |
40 | | - audio.play(my_recording, wait=False) |
| 44 | + audio.play(my_track, wait=False) |
41 | 45 | level = 0 |
42 | 46 | while audio.is_playing(): |
43 | 47 | l = audio.sound_level() |
|
47 | 51 | level *= 0.95 |
48 | 52 | display.show(play * min(1, level / 100)) |
49 | 53 | x = accelerometer.get_x() |
50 | | - my_recording.set_rate(max(2250, scale(x, (-1000, 1000), (2250, 13374)))) |
| 54 | + my_track.set_rate(max(2250, scale(x, (-1000, 1000), (2250, 13374)))) |
51 | 55 | sleep(5) |
52 | 56 | display.clear() |
53 | 57 | sleep(100) |
0 commit comments