Skip to content

Commit d44f608

Browse files
authored
Merge pull request #3165 from RetiredWizard/animalsounds
Spell_Jam: Add word sounds
2 parents 518d5f0 + 1f5fbdb commit d44f608

File tree

1 file changed

+25
-0
lines changed
  • Fruit_Jam/Fruit_Jam_Spell_Jam

1 file changed

+25
-0
lines changed

Fruit_Jam/Fruit_Jam_Spell_Jam/code.py

Lines changed: 25 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

@@ -63,6 +64,28 @@
6364

6465
word_fetcher = WordFetcherTTS(fj, launcher_config)
6566

67+
def play_sound():
68+
soundPath = None
69+
if 'words' in os.listdir('spell_jam_assets'):
70+
soundPath = 'spell_jam_assets/words/'
71+
else:
72+
try:
73+
sdAssets = os.listdir('/sd/spell_jam_assets/')
74+
soundPath = f"/sd/spell_jam_assets/{sdAssets[sdAssets.index('words')]}/"
75+
except ValueError:
76+
soundPath = None
77+
except OSError:
78+
soundPath = None
79+
80+
if soundPath is not None:
81+
for sound in os.listdir(soundPath):
82+
if sound.upper()[:-4] == lastword.upper():
83+
if sound[-4:] == ".mp3":
84+
fj.play_mp3_file(f'{soundPath}{sound}')
85+
elif sound[-4:] == ".wav":
86+
fj.play_file(f'{soundPath}{sound}')
87+
break
88+
6689
def say_and_spell_lastword():
6790
"""
6891
Say the last word, then spell it out one letter at a time, finally say it once more.
@@ -81,6 +104,8 @@ def say_and_spell_lastword():
81104
fj.play_mp3_file(word_fetcher.output_path)
82105
elif word_fetcher.output_path[-4:] == ".wav":
83106
fj.play_file(word_fetcher.output_path)
107+
play_sound()
108+
84109
fj.neopixels.fill(0x000000)
85110

86111

0 commit comments

Comments
 (0)