11# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
22# SPDX-License-Identifier: MIT
3- import os
3+
44import sys
55import time
6-
76import supervisor
7+
88from adafruit_fruitjam import FruitJam
99from adafruit_fruitjam .peripherals import request_display_config
10- import adafruit_connection_manager
11- import adafruit_requests
1210from displayio import OnDiskBitmap , TileGrid , Group
1311from adafruit_bitmap_font import bitmap_font
1412from adafruit_display_text .bitmap_label import Label
1513
16- from aws_polly import text_to_speech_polly_http
17-
1814from launcher_config import LauncherConfig
1915
16+ # comment out one of these imports depending on which TTS engine you want to use
17+ from tts_aws import WordFetcherTTS
18+ # from tts_local import WordFetcherTTS
19+
20+ # read the user settings
2021launcher_config = LauncherConfig ()
2122
2223# constants
6061
6162fj .neopixels .brightness = 0.1
6263
63- # AWS auth requires us to have accurate date/time
64- now = fj .sync_time ()
65-
66- # setup adafruit_requests session
67- # pylint: disable=protected-access
68- pool = adafruit_connection_manager .get_radio_socketpool (fj .network ._wifi .esp )
69- ssl_context = adafruit_connection_manager .get_radio_ssl_context (fj .network ._wifi .esp )
70- requests = adafruit_requests .Session (pool , ssl_context )
71-
72- # read AWS keys from settings.toml
73- AWS_ACCESS_KEY = os .getenv ("AWS_ACCESS_KEY" )
74- AWS_SECRET_KEY = os .getenv ("AWS_SECRET_KEY" )
75-
76-
77- def fetch_word (word , voice = "Joanna" ):
78- """
79- Fetch an MP3 saying a word from AWS Polly
80- :param word: The word to speak
81- :param voice: The AWS Polly voide ID to use
82- :return: Boolean, whether the request was successful.
83- """
84-
85- if AWS_ACCESS_KEY is None or AWS_SECRET_KEY is None :
86- return False
87-
88- fj .neopixels .fill (0xFFFF00 )
89- success = text_to_speech_polly_http (
90- requests ,
91- text = word ,
92- access_key = AWS_ACCESS_KEY ,
93- secret_key = AWS_SECRET_KEY ,
94- voice_id = voice ,
95- )
96- fj .neopixels .fill (0x00FF00 )
97- return success
98-
64+ word_fetcher = WordFetcherTTS (fj , launcher_config )
9965
10066def say_and_spell_lastword ():
10167 """
10268 Say the last word, then spell it out one letter at a time, finally say it once more.
10369 """
10470 if sayword :
105- fj .play_mp3_file ("/saves/awspollyoutput.mp3" )
71+ if word_fetcher .output_path [- 4 :] == ".mp3" :
72+ fj .play_mp3_file (word_fetcher .output_path )
73+ elif word_fetcher .output_path [- 4 :] == ".wav" :
74+ fj .play_file (word_fetcher .output_path )
10675 time .sleep (0.2 )
10776 for letter in lastword :
10877 fj .play_mp3_file (f"spell_jam_assets/letter_mp3s/{ letter .upper ()} .mp3" )
10978 time .sleep (0.2 )
11079 if sayword :
111- fj .play_mp3_file ("/saves/awspollyoutput.mp3" )
80+ if word_fetcher .output_path [- 4 :] == ".mp3" :
81+ fj .play_mp3_file (word_fetcher .output_path )
82+ elif word_fetcher .output_path [- 4 :] == ".wav" :
83+ fj .play_file (word_fetcher .output_path )
11284 fj .neopixels .fill (0x000000 )
11385
11486
@@ -133,7 +105,7 @@ def say_and_spell_lastword():
133105 elif c == "\n " :
134106 if curword :
135107 lastword = curword
136- sayword = fetch_word (lastword )
108+ sayword = word_fetcher . fetch_word (lastword )
137109 say_and_spell_lastword ()
138110 curword = ""
139111 else :
0 commit comments