Skip to content

Commit 28c26a1

Browse files
authored
Merge pull request #3136 from RetiredWizard/fruitspelljam
Spell_Jam: avoid crash when aws isn't used, use audio settings
2 parents cf98466 + 8947a6d commit 28c26a1

File tree

1 file changed

+27
-6
lines changed
  • Fruit_Jam/Fruit_Jam_Spell_Jam

1 file changed

+27
-6
lines changed

Fruit_Jam/Fruit_Jam_Spell_Jam/code.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515

1616
from aws_polly import text_to_speech_polly_http
1717

18+
from launcher_config import LauncherConfig
19+
20+
launcher_config = LauncherConfig()
21+
1822
# constants
1923
LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
2024

2125
# local variables
2226
curword = ""
2327
lastword = ""
28+
sayword = False
2429

2530
# setup display
2631
request_display_config(320, 240)
@@ -41,9 +46,19 @@
4146

4247
# initialize Fruit Jam built-in hardware
4348
fj = FruitJam()
49+
50+
if "audio" in launcher_config.data and "volume" in launcher_config.data["audio"]:
51+
volume_level = launcher_config.audio_volume
52+
else:
53+
volume_level = 0.5
54+
55+
fj.peripherals.audio_output = launcher_config.audio_output
56+
fj.peripherals.safe_volume_limit = launcher_config.audio_volume_override_danger
57+
58+
fj.peripherals.volume = volume_level
59+
vol_int = round(volume_level * 100)
60+
4461
fj.neopixels.brightness = 0.1
45-
fj.peripherals.volume = 0.5
46-
vol_int = 50
4762

4863
# AWS auth requires us to have accurate date/time
4964
now = fj.sync_time()
@@ -66,6 +81,10 @@ def fetch_word(word, voice="Joanna"):
6681
:param voice: The AWS Polly voide ID to use
6782
:return: Boolean, whether the request was successful.
6883
"""
84+
85+
if AWS_ACCESS_KEY is None or AWS_SECRET_KEY is None:
86+
return False
87+
6988
fj.neopixels.fill(0xFFFF00)
7089
success = text_to_speech_polly_http(
7190
requests,
@@ -82,12 +101,14 @@ def say_and_spell_lastword():
82101
"""
83102
Say the last word, then spell it out one letter at a time, finally say it once more.
84103
"""
85-
fj.play_mp3_file("/saves/awspollyoutput.mp3")
86-
time.sleep(0.2)
104+
if sayword:
105+
fj.play_mp3_file("/saves/awspollyoutput.mp3")
106+
time.sleep(0.2)
87107
for letter in lastword:
88108
fj.play_mp3_file(f"spell_jam_assets/letter_mp3s/{letter.upper()}.mp3")
89109
time.sleep(0.2)
90-
fj.play_mp3_file("/saves/awspollyoutput.mp3")
110+
if sayword:
111+
fj.play_mp3_file("/saves/awspollyoutput.mp3")
91112
fj.neopixels.fill(0x000000)
92113

93114

@@ -112,7 +133,7 @@ def say_and_spell_lastword():
112133
elif c == "\n":
113134
if curword:
114135
lastword = curword
115-
fetch_word(lastword)
136+
sayword = fetch_word(lastword)
116137
say_and_spell_lastword()
117138
curword = ""
118139
else:

0 commit comments

Comments
 (0)