youngtsai commited on
Commit
a6fb9ef
·
1 Parent(s): 96e8ee6
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -2,6 +2,8 @@ import os
2
  import gradio as gr
3
  from openai import OpenAI
4
  import json
 
 
5
 
6
 
7
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
@@ -271,12 +273,11 @@ def paragraph_save_and_tts(paragraph_text):
271
  input=paragraph_text,
272
  )
273
 
274
- # Define the path for the audio file in the /mnt/data/ directory
275
- audio_path = "/mnt/data/generated_audio_openai.mp3"
276
 
277
- # Save the audio stream to a file in the /mnt/data/ directory
278
- with open(audio_path, "wb") as audio_file:
279
- audio_file.write(response.data)
280
 
281
  # Return the path to the audio file along with the text
282
  return paragraph_text, audio_path
 
2
  import gradio as gr
3
  from openai import OpenAI
4
  import json
5
+ import tempfile
6
+
7
 
8
 
9
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
 
273
  input=paragraph_text,
274
  )
275
 
276
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
277
+ temp_file.write(response.content)
278
 
279
+ # Get the file path of the temp file
280
+ audio_path = temp_file.name
 
281
 
282
  # Return the path to the audio file along with the text
283
  return paragraph_text, audio_path