Skip to content

Commit 2ae9725

Browse files
committed
Update dice.py
add voice
1 parent ae2df81 commit 2ae9725

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

software/dice.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
'''
2+
https://github.com/MakerM0/MagiClick-esp32s3
3+
4+
v0.3.0
5+
20230922
6+
add voice
7+
8+
29
v0.2.0
310
20230723
411
add bmp
@@ -11,9 +18,33 @@
1118
import asyncio
1219
import random
1320
import terminalio
14-
1521

22+
import audiocore
23+
import board
24+
import audiobusio
25+
1626

27+
voice = ["1", "ai", "3", "4", "5", "6"]
28+
29+
def playwave(filename):
30+
audiopwr_on()
31+
i2s = audiobusio.I2SOut(AUDIO_BCK,AUDIO_WS,AUDIO_DATA)
32+
try :
33+
wave_file = open('audio/cn_girl/{}'.format(filename), "rb")
34+
wave = audiocore.WaveFile(wave_file)
35+
i2s.play(wave)
36+
while i2s.playing:
37+
pass
38+
wave.deinit()
39+
wave_file.close()
40+
wave_file=None
41+
gc.collect()
42+
43+
except Exception as e :
44+
print (e)
45+
i2s.deinit()
46+
audiopwr_off()
47+
pass
1748

1849
class Dice:
1950
def __init__(self):
@@ -78,6 +109,7 @@ async def draw(dice):
78109
tile_grid.x = display.width//2-50 +random.randint(-10,10)
79110
tile_grid.y = display.height//2-50+random.randint(-10,10)
80111
if time.monotonic()-starttick >= TICK_DICE:
112+
playwave("{}.wav".format(voice[dice.value]))
81113
dice.f_loop=False
82114
dice.f_stop=True
83115

@@ -123,6 +155,13 @@ async def button_handle(dice):
123155
#
124156
async def main():
125157
dice =Dice()
158+
159+
# playwave("{}.wav".format(voice[0]))
160+
# playwave("{}.wav".format(voice[1]))
161+
# playwave("{}.wav".format(voice[2]))
162+
# playwave("{}.wav".format(voice[3]))
163+
# playwave("{}.wav".format(voice[4]))
164+
# playwave("{}.wav".format(voice[5]))
126165

127166

128167

0 commit comments

Comments
 (0)