File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 6
6
# SD card. Default pinout matches the Audio BFF for QT Py S2, S3 and RP2040
7
7
8
8
import os
9
- import time
9
+ import random
10
10
import audiocore
11
11
import board
12
12
import audiobusio
13
13
import audiomixer
14
14
import adafruit_sdcard
15
15
import storage
16
16
import digitalio
17
- import random
18
17
19
18
card_cs = digitalio .DigitalInOut (board .A0 )
20
19
card_cs .direction = digitalio .Direction .INPUT
36
35
if filename .endswith (".wav" ) and not filename .startswith ("." ):
37
36
wave_files .append (filename )
38
37
38
+ def open_audio ():
39
+ n = random .choice (wave_files )
40
+ print ("playing" , n )
41
+ f = open (n , "rb" )
42
+ w = audiocore .WaveFile (f )
43
+ return f , w
44
+
45
+ wavefile = 0
46
+
39
47
while True :
40
48
if not sdcard :
41
49
try :
56
64
if wavefile :
57
65
wavefile .close ()
58
66
else :
59
- name = random .choice (wave_files )
60
- print ("playing" , name )
61
- wavefile = open (name , "rb" )
62
- wave = audiocore .WaveFile (wavefile )
67
+ wavefile , wave = open_audio ()
63
68
mixer = audiomixer .Mixer (voice_count = 1 ,
64
69
sample_rate = wave .sample_rate ,
65
70
channel_count = wave .channel_count ,
You can’t perform that action at this time.
0 commit comments