-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolly.py
More file actions
237 lines (228 loc) · 10.3 KB
/
Copy pathpolly.py
File metadata and controls
237 lines (228 loc) · 10.3 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import boto3
import os
# Create a directory to store audio files if it doesn't exist
output_directory = "audio"
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# Initialize Polly client
# Ensure you have your AWS credentials configured correctly (e.g., via environment variables, IAM roles, or a credentials file)
polly = boto3.client('polly', region_name='us-east-1')
files = [
{
"filename": "audio/intro_1.mp3",
"voice": "Matthew-Neural", # Using the VoiceId directly
"language": "en-US",
"ssml": '<speak>This is an interactive journey through the Forest of Disconnect storybook.<break time="0.5s"/> You will join five travelers as they learn to defuse the <emphasis level="moderate">emotional bombs</emphasis> of cynicism and judgment to find connection.<break time="0.5s"/> Click "Begin" to start.</speak>'
},
{
"filename": "audio/chapter1_narrator_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>In a vast land, there was a dense, misty place called the <say-as interpret-as="characters">Forest of Disconnect</say-as>.<break time="0.7s"/> Five travelers arrived: Kai, who guarded his thoughts with sharp words;<break time="0.3s"/> Mara, quick to voice her worries;<break time="0.3s"/> Tomas, slow but wise;<break time="0.3s"/> Sana, quiet but observant;<break time="0.3s"/> and Eli, humming softly, seeking clarity.<break time="0.5s"/> Their guide, Lina, held a glowing lantern and a map: <say-as interpret-as="characters">Lina’s Compass of Connection</say-as>.</speak>'
},
{
"filename": "audio/chapter1_lina_1.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak><prosody rate="0.9">This forest holds <emphasis level="strong">emotional bombs</emphasis>—spiky barriers of cynicism and judgment that block our path to connection.<break time="0.5s"/> Defusing them means softening their power with understanding.<break time="0.5s"/> Will you join me with open minds and <emphasis level="moderate">kind hearts</emphasis>?</prosody></speak>'
},
{
"filename": "audio/chapter1_narrator_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>The travelers nodded, though some looked skeptical.<break time="0.4s"/> Eli hummed softly, eyeing the foggy path.</speak>'
},
{
"filename": "audio/chapter1_kai_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>This seems like a waste of time. I doubt we\'ll find anything useful here.</speak>'
},
{
"filename": "audio/chapter1_mara_1.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Are you sure we should go in? What if something bad happens?</speak>'
},
{
"filename": "audio/chapter1_lina_2.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Fear and doubt are natural, but they can be the first "bombs" to disarm.<break time="0.5s"/> Let my compassion be your guide as you explore your own hearts and minds.</speak>'
},
{
"filename": "audio/chapter2_narrator_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>They walked deeper, the mist clinging to them.<break time="0.4s"/> A large, thorny bush blocked the way.<break time="0.5s"/> From it emerged a thorny ball of negativity—a Cynicism Bomb.<break time="0.8s"/> It crackled with defensive energy.</speak>'
},
{
"filename": "audio/chapter2_cynicism_bomb_1.mp3",
"voice": "Salli", # Or another appropriate voice
"language": "en-US",
"ssml": '<speak>Bah! What\'s the point? This is hopeless!</speak>'
},
{
"filename": "audio/chapter2_kai_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>See? I told you this was a waste of time!</speak>'
},
{
"filename": "audio/chapter2_lina_3.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>This bomb feeds on our negativity, Kai.<break time="0.5s"/> Try speaking to it with understanding instead of judgment.</speak>'
},
{
"filename": "audio/chapter2_kai_3.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak><prosody pitch="-10%">It... it must be hard to feel so hopeless.</prosody></speak>'
},
{
"filename": "audio/chapter2_narrator_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>The Cynicism Bomb’s thorns softened slightly.<break time="0.5s"/> Lina smiled.</speak>'
},
{
"filename": "audio/chapter2_lina_4.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Well done, Kai! Understanding is the first step to defusing cynicism.</speak>'
},
{
"filename": "audio/chapter3_narrator_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>Further on, they encountered a rigid wall of disapproval.<break time="0.6s"/> A Judgment Bomb radiated icy critiques.<break time="0.8s"/> It spoke with harsh, critical words.</speak>'
},
{
"filename": "audio/chapter3_judgment_bomb_1.mp3",
"voice": "Amy", # Or another appropriate voice
"language": "en-US",
"ssml": '<speak>You\'re not doing it right! You\'ll never succeed!</speak>'
},
{
"filename": "audio/chapter3_mara_2.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>It knows my deepest fears!</speak>'
},
{
"filename": "audio/chapter3_lina_5.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>This bomb thrives on our self-doubt, Mara.<break time="0.5s"/> Try speaking with self-compassion.</speak>'
},
{
"filename": "audio/chapter3_mara_3.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak><prosody rate="0.8">I am doing my best, and that is enough.</prosody></speak>'
},
{
"filename": "audio/chapter3_narrator_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>The Judgment Bomb’s icy surface cracked.<break time="0.5s"/> Lina nodded encouragingly.</speak>'
},
{
"filename": "audio/chapter3_lina_6.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Excellent, Mara! Self-compassion melts the ice of judgment.</speak>'
},
{
"filename": "audio/chapter4_narrator_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>Tomas, the thoughtful traveler, noticed a dense fog of confusion.<break time="0.6s"/> Within it swirled a bomb of Uncertainty.<break time="0.8s"/> It pulsed with hesitant energy.</speak>'
},
{
"filename": "audio/chapter4_uncertainty_bomb_1.mp3",
"voice": "Joey", # Or another appropriate voice
"language": "en-US",
"ssml": '<speak>What if I make the wrong choice? I don\'t know what to do!</speak>'
},
{
"filename": "audio/chapter4_tomas_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>This bomb speaks to my own hesitations.</speak>'
},
{
"filename": "audio/chapter4_lina_7.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Uncertainty stems from seeking perfect answers, Tomas.<break time="0.5s"/> Speak to it with gentle acceptance of the unknown.</speak>'
},
{
"filename": "audio/chapter4_tomas_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak><prosody volume="soft">It is okay not to know everything.</prosody></speak>'
},
{
"filename": "audio/chapter4_narrator_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>The Uncertainty Bomb\'s fog thinned.<break time="0.5s"/> Lina smiled.</speak>'
},
{
"filename": "audio/chapter4_lina_8.mply",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Wisely spoken, Tomas! Acceptance clears the fog of uncertainty.</speak>'
},
{
"filename": "audio/chapter5_narrator_1.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>Sana, the quiet one, felt a chill from a distant Isolation Bomb.<break time="0.6s"/> It vibrated with a lonely hum.<break time="0.8s"/> It seemed to say nothing, but its silence was a heavy weight.</speak>'
},
{
"filename": "audio/chapter5_isolation_bomb_1.mp3",
"voice": "Kendra", # Or another appropriate voice
"language": "en-US",
"ssml": '<speak><prosody rate="x-slow">No one understands. I am alone.</prosody></speak>'
},
{
"filename": "audio/chapter5_sana_1.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Its silence speaks of deep sadness.</speak>'
},
{
"filename": "audio/chapter5_lina_9.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak>Isolation thrives in silence, Sana.<break time="0.5s"/> Speak to it with connection, even if it feels small.</speak>'
},
{
"filename": "audio/chapter5_sana_2.mp3",
"voice": "Joanna-Neural",
"language": "en-US",
"ssml": '<speak><prosody rate="x-slow" volume="loud">You are not alone.</prosody></speak>'
},
{
"filename": "audio/chapter5_narrator_2.mp3",
"voice": "Matthew-Neural",
"language": "en-US",
"ssml": '<speak>The Isolation Bomb\'s hum faded.<break time="0.5s"/> Lina smiled gently.</speak>'
},
]
for file_info in files:
try:
response = polly.synthesize_speech(
Text=file_info["ssml"],
VoiceId=file_info["voice"],
OutputFormat='mp3',
TextType='ssml' # Specify text type as SSML
)
with open(file_info["filename"], 'wb') as audio_file:
audio_file.write(response['AudioStream'].read())
print(f"Successfully generated {file_info['filename']}")
except Exception as e:
print(f"Error generating {file_info['filename']}: {e}")