MariaKaiser commited on
Commit
2d49f87
·
verified ·
1 Parent(s): e238909

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -132,8 +132,28 @@ import asyncio
132
  # print(f"All {retries} attempts failed for {url}")
133
  # return None
134
 
 
135
  download_cache = {}
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  async def download_file_from_url(url: str, retries: int = 3, delay: float = 2.0) -> str | None:
138
  """
139
  Downloads a file from a URL and returns the path to a temporary file.
@@ -218,13 +238,14 @@ async def generate_story_audios(story: StoryCreationDTO, base_output: str):
218
  # os.remove(prosody_file_title)
219
 
220
  for scene in chapter.scenes:
 
221
  scene_dir = chapter_dir / scene.sceneId
222
  scene_dir.mkdir(exist_ok=True)
223
 
224
  # --- Sentences audio ---
225
  for sentence in scene.sentences:
226
  # Download the prosody reference audio from Supabase
227
- prosody_file = await download_file_from_url(sentence.prosodyReference)
228
  sentence_save_path = scene_dir / f"{sentence.sentenceId}.wav"
229
  tagged_text = generate_tagged_text(
230
  sentence.sentence,
 
132
  # print(f"All {retries} attempts failed for {url}")
133
  # return None
134
 
135
+
136
  download_cache = {}
137
 
138
+ async def download_scene_files(scene: SceneDto):
139
+ tasks = []
140
+
141
+ # Sentence prosody references
142
+ for sentence in scene.sentences:
143
+ tasks.append(download_file_from_url(sentence.prosodyReference))
144
+
145
+ # Location SFX
146
+ if scene.location.path:
147
+ tasks.append(download_file_from_url(scene.location.path))
148
+
149
+ # Background music
150
+ if scene.bgMusic and scene.bgMusic.musicPath:
151
+ tasks.append(download_file_from_url(scene.bgMusic.musicPath))
152
+
153
+ # Run all downloads concurrently
154
+ downloaded_files = await asyncio.gather(*tasks)
155
+ return downloaded_files
156
+
157
  async def download_file_from_url(url: str, retries: int = 3, delay: float = 2.0) -> str | None:
158
  """
159
  Downloads a file from a URL and returns the path to a temporary file.
 
238
  # os.remove(prosody_file_title)
239
 
240
  for scene in chapter.scenes:
241
+ await download_scene_files(scene)
242
  scene_dir = chapter_dir / scene.sceneId
243
  scene_dir.mkdir(exist_ok=True)
244
 
245
  # --- Sentences audio ---
246
  for sentence in scene.sentences:
247
  # Download the prosody reference audio from Supabase
248
+ prosody_file = download_cache[sentence.prosodyReference]
249
  sentence_save_path = scene_dir / f"{sentence.sentenceId}.wav"
250
  tagged_text = generate_tagged_text(
251
  sentence.sentence,