Skip to content

Commit b14b39e

Browse files
committed
Spell_Jam: Add word sounds
1 parent 59524df commit b14b39e

File tree

1 file changed

+22
-0
lines changed
  • Fruit_Jam/Fruit_Jam_Spell_Jam

1 file changed

+22
-0
lines changed

Fruit_Jam/Fruit_Jam_Spell_Jam/code.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
import sys
5+
import os
56
import time
67
import supervisor
78

@@ -81,6 +82,27 @@ def say_and_spell_lastword():
8182
fj.play_mp3_file(word_fetcher.output_path)
8283
elif word_fetcher.output_path[-4:] == ".wav":
8384
fj.play_file(word_fetcher.output_path)
85+
soundPath = None
86+
if 'words' in os.listdir('spell_jam_assets'):
87+
soundPath = 'spell_jam_assets/words/'
88+
else:
89+
try:
90+
sdAssets = os.listdir('/sd/spell_jam_assets/')
91+
soundPath = f"/sd/spell_jam_assets/{sdAssets[sdAssets.index('words')]}/"
92+
except ValueError:
93+
soundPath = None
94+
except OSError:
95+
soundPath = None
96+
97+
if soundPath is not None:
98+
for sound in os.listdir(soundPath):
99+
if sound.upper()[:-4] == lastword.upper():
100+
if sound[-4:] == ".mp3":
101+
fj.play_mp3_file(f'{soundPath}{sound}')
102+
elif sound[-4:] == ".wav":
103+
fj.play_file(f'{soundPath}{sound}')
104+
break
105+
84106
fj.neopixels.fill(0x000000)
85107

86108

0 commit comments

Comments
 (0)