Skip to content

Commit 1e73508

Browse files
committed
better backend selection and additional documentation
1 parent ff390fb commit 1e73508

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

Fruit_Jam/Fruit_Jam_Spell_Jam/code.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
22
# SPDX-License-Identifier: MIT
3+
4+
import os
35
import sys
46
import time
57
import supervisor
@@ -12,12 +14,12 @@
1214

1315
from launcher_config import LauncherConfig
1416

15-
# If tts_local.py exists, use that instead of tts_aws.py
16-
try:
17+
# choose AWS TTS engine if AWS credentials are set in environment variables
18+
if os.getenv("AWS_ACCESS_KEY") is not None and os.getenv("AWS_SECRET_KEY") is not None:
19+
from tts_aws import WordFetcherTTS
20+
else:
1721
# tts_local defines WordFetcherTTS for TTS engine running on local network server
1822
from tts_local import WordFetcherTTS
19-
except ImportError:
20-
from tts_aws import WordFetcherTTS
2123

2224
# read the user settings
2325
launcher_config = LauncherConfig()

Fruit_Jam/Fruit_Jam_Spell_Jam/tts_local.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
# SPDX-FileCopyrightText: 2025 RetiredWizard
22
# SPDX-License-Identifier: MIT
33

4+
"""
5+
Kani TTS engine for Fruit Jam Spell Jam. Install and run the kani-tts AI server on your
6+
local network following the instructions at: https://github.com/nineninesix-ai/kani-tts
7+
8+
The server.py script from the kani-tts repo needs to be modified to create 16bit WAV files
9+
instead of the default 32bit WAV files. Change the following lines in server.py
10+
11+
# Convert to WAV bytes
12+
wav_buffer = io.BytesIO()
13+
wav_write(wav_buffer, 22050, full_audio)
14+
wav_buffer.seek(0)
15+
to:
16+
# Convert float32 audio (-1.0 to 1.0) to 16-bit PCM
17+
audio_int16 = np.clip(full_audio, -1.0, 1.0)
18+
audio_int16 = (audio_int16 * 32767).astype(np.int16)
19+
20+
# Write as 16-bit WAV
21+
wav_buffer = io.BytesIO()
22+
wav_write(wav_buffer, 22050, audio_int16)
23+
wav_buffer.seek(0)
24+
25+
Then configure the server endpoint in launcher.conf.json, e.g.:
26+
"spell_jam": {
27+
"tts_server_endpoint": "http://myserver.local:8000"
28+
}
29+
"""
30+
431
# tts_kani.py
532
import json
633
import adafruit_connection_manager

0 commit comments

Comments
 (0)