forked from ctxis/Furby
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_toccata.py
More file actions
195 lines (156 loc) · 7.16 KB
/
demo_toccata.py
File metadata and controls
195 lines (156 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# demo_toccata.py
#
# Copyright 2017 Ed Locard (@L0C4RD)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
"""
Demo script for making Furby play Toccata and Fugue in D Minor by J.S. Bach
This script demonstrates how to replace Furby's audio responses with
the famous Toccata and Fugue in D Minor. The haunting organ piece is
perfect for giving your Furby a dramatic, theatrical personality.
REQUIREMENTS:
- Python 2.7 (this codebase uses Python 2 syntax)
- A Furby Connect DLC file (e.g., ./dlc/dlc2/tu003410.dlc)
- Toccata audio file in .a18 format (see audio/new_audio/README.md for conversion instructions)
- Pillow library installed (pip install Pillow)
USAGE:
python2 demo_toccata.py
OR if Python 2 is your default:
python demo_toccata.py
The script will create a new DLC file (toccata_furby.dlc) that can be
uploaded to your Furby Connect.
NOTE: If you get syntax errors about 'print' statements, you are running
Python 3. This project requires Python 2.7.
"""
from furby import dlc
import os
def make_toccata_furby(dlc_in="./dlc/dlc2/tu003410.dlc",
toccata_audio="./audio/new_audio/toccata_in_d_minor.a18",
dlc_out="./toccata_furby.dlc",
minify=False):
"""
Create a Furby DLC that plays Toccata in D Minor.
This function takes an existing Furby Connect DLC file and replaces
audio for specific action codes with the Toccata in D Minor audio.
Args:
dlc_in: Path to the input DLC file
toccata_audio: Path to the Toccata audio file in .a18 format
dlc_out: Path for the output DLC file
minify: If True, shrink other audio tracks for faster testing (default: False)
Returns:
None
Raises:
OSError: If the input DLC file doesn't exist
"""
# Check if files exist
if not os.path.exists(dlc_in):
raise OSError("Input DLC file not found: %s" % dlc_in)
if not os.path.exists(toccata_audio):
print("WARNING: Toccata audio file not found: %s" % toccata_audio)
print("Please prepare a Toccata in D Minor audio file in .a18 format.")
print("See audio/new_audio/README.md for instructions on audio conversion.")
return
print("Loading DLC file...")
D = dlc(dlc_in)
# Optionally minify audio to speed up testing (disabled by default)
if minify:
print("Minifying existing audio tracks for faster testing...")
D.dlc_sections["AMF"].minify_audio()
else:
print("Keeping original audio tracks intact...")
# Replace audio for action code 75-0-0-0 (button press)
# This is a common action code triggered by user interaction
print("Replacing audio for action code 75-0-0-0 with Toccata...")
try:
D.replace_audio((75, 0, 0, 0), [toccata_audio])
except Exception as e:
print("Error replacing audio for action code 75-0-0-0: %s" % e)
# Replace audio for action code 75-0-0-1 (alternative button press)
print("Replacing audio for action code 75-0-0-1 with Toccata...")
try:
D.replace_audio((75, 0, 0, 1), [toccata_audio])
except Exception as e:
print("Error replacing audio for action code 75-0-0-1: %s" % e)
# Replace audio for action code 75-0-0-3 (another common action)
print("Replacing audio for action code 75-0-0-3 with Toccata...")
try:
D.replace_audio((75, 0, 0, 3), [toccata_audio])
except Exception as e:
print("Error replacing audio for action code 75-0-0-3: %s" % e)
# Build the new DLC file
print("Building new DLC file: %s" % dlc_out)
D.build(dlc_out)
print("Done! Your Toccata-enabled Furby DLC is ready.")
print("Upload %s to your Furby Connect to hear it play Toccata in D Minor!" % dlc_out)
print("\nNOTE: Be careful when uploading custom DLCs - bad DLCs can make your Furby unhappy.")
def create_multi_track_toccata(dlc_in="./dlc/dlc2/tu003410.dlc",
toccata_intro="./audio/new_audio/toccata_intro.a18",
toccata_main="./audio/new_audio/toccata_main.a18",
toccata_climax="./audio/new_audio/toccata_climax.a18",
dlc_out="./toccata_furby_multi.dlc",
minify=False):
"""
Create a Furby DLC with multiple segments of Toccata in D Minor.
This advanced function allows you to split the Toccata into multiple
parts and have them play at different times or as a sequence.
Args:
dlc_in: Path to the input DLC file
toccata_intro: Path to intro section of Toccata (.a18 format)
toccata_main: Path to main section of Toccata (.a18 format)
toccata_climax: Path to climax section of Toccata (.a18 format)
dlc_out: Path for the output DLC file
minify: If True, shrink other audio tracks for faster testing (default: False)
Returns:
None
"""
# Check if files exist
if not os.path.exists(dlc_in):
raise OSError("Input DLC file not found: %s" % dlc_in)
audio_files = [toccata_intro, toccata_main, toccata_climax]
missing_files = [f for f in audio_files if not os.path.exists(f)]
if missing_files:
print("WARNING: Audio files not found: %s" % missing_files)
print("Please prepare Toccata audio segments in .a18 format.")
print("See audio/new_audio/README.md for instructions.")
return
print("Loading DLC file...")
D = dlc(dlc_in)
# Optionally minify audio to speed up testing (disabled by default)
if minify:
print("Minifying existing audio tracks for faster testing...")
D.dlc_sections["AMF"].minify_audio()
else:
print("Keeping original audio tracks intact...")
# Replace with a sequence of Toccata segments
print("Replacing audio for action code 75-0-0-0 with Toccata segments...")
try:
D.replace_audio((75, 0, 0, 0), [toccata_intro, toccata_main, toccata_climax])
except Exception as e:
print("Error: %s" % e)
# Build the new DLC file
print("Building new DLC file: %s" % dlc_out)
D.build(dlc_out)
print("Done! Your multi-track Toccata Furby DLC is ready.")
if __name__ == "__main__":
# Try to create the Toccata Furby
make_toccata_furby()
# Uncomment the following line to create a multi-track version instead:
# create_multi_track_toccata()