Gregniuki commited on
Commit
268fc4f
·
1 Parent(s): 23dca17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -153,7 +153,18 @@ async def main(
153
 
154
  # Rename the audio file based on the text input
155
  renamed_audio_file = os.path.join(temp_dir, f"{text_input}.mp3")
156
- audio.export(renamed_audio_file, format="mp3")
 
 
 
 
 
 
 
 
 
 
 
157
  # os.rename(temp_audio_file, renamed_audio_file)
158
  # Specify the path to your MP3 audio file
159
  # audio_file_path = "path/to/your/audio.mp3"
@@ -215,17 +226,27 @@ async def main(
215
  # display(speaker_selection)
216
 
217
 
218
-
219
 
220
 
221
  # Save the audio as a temporary WAV file
222
- # return templates.TemplateResponse("interface.html", {"request": request, "audio_file": renamed_audio_file, "data": data})
223
 
224
  # Serve the audio file with the correct media type
225
- return FileResponse(renamed_audio_file)
 
226
 
 
227
 
228
- # return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
 
 
 
 
 
 
 
 
229
 
230
  def load_onnx(model, sess_options, providers = ["CPUExecutionProvider"]):
231
  _LOGGER.debug("Loading model from %s", model)
 
153
 
154
  # Rename the audio file based on the text input
155
  renamed_audio_file = os.path.join(temp_dir, f"{text_input}.mp3")
156
+ # audio.export(renamed_audio_file, format="mp3")
157
+ # Save the generated audio as a temporary file
158
+ filepath = renamed_audio_file
159
+
160
+ # Generate a unique file ID
161
+ file_id = str(uuid.uuid4())
162
+
163
+ # Store the file path with the generated file ID
164
+ files[file_id] = filepath
165
+
166
+ # Create a URL to download the file
167
+ file_url = f'/download?fileId={file_id}'
168
  # os.rename(temp_audio_file, renamed_audio_file)
169
  # Specify the path to your MP3 audio file
170
  # audio_file_path = "path/to/your/audio.mp3"
 
226
  # display(speaker_selection)
227
 
228
 
229
+
230
 
231
 
232
  # Save the audio as a temporary WAV file
233
+ return templates.TemplateResponse("interface.html", {"request": request, "audio_file": renamed_audio_file, "fileURL": file_url, "data": data})
234
 
235
  # Serve the audio file with the correct media type
236
+ # return FileResponse(renamed_audio_file)
237
+
238
 
239
+ # return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
240
 
241
+ @app.get("/download/")
242
+ async def download_file(fileId: str):
243
+ # Retrieve the file path from the dictionary using the file ID
244
+ filepath = files.get(fileId)
245
+ if filepath:
246
+ # Create a FileResponse to serve the file for download
247
+ return FileResponse(filepath, headers={"Content-Disposition": "attachment"})
248
+ else:
249
+ return {"error": "File not found"}
250
 
251
  def load_onnx(model, sess_options, providers = ["CPUExecutionProvider"]):
252
  _LOGGER.debug("Loading model from %s", model)