Spaces:
Sleeping
Sleeping
response = OPEN_AI_CLIENT.audio.speech.create(
Browse files- app.py +18 -11
- requirements.txt +0 -2
app.py
CHANGED
@@ -269,22 +269,29 @@ def paragraph_save(refine_paragraph):
|
|
269 |
|
270 |
def paragraph_save_and_tts(paragraph_text):
|
271 |
"""
|
272 |
-
Saves the paragraph text and generates an audio file using
|
273 |
"""
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
|
|
|
|
276 |
|
277 |
-
|
278 |
-
|
279 |
|
280 |
-
|
281 |
-
|
282 |
|
283 |
-
|
284 |
-
|
285 |
|
286 |
-
|
287 |
-
|
|
|
|
|
288 |
|
289 |
with gr.Blocks() as demo:
|
290 |
with gr.Row():
|
|
|
269 |
|
270 |
def paragraph_save_and_tts(paragraph_text):
|
271 |
"""
|
272 |
+
Saves the paragraph text and generates an audio file using OpenAI's TTS.
|
273 |
"""
|
274 |
+
try:
|
275 |
+
# Call OpenAI's TTS API to generate speech from text
|
276 |
+
response = OPEN_AI_CLIENT.audio.speech.create(
|
277 |
+
model="tts-1",
|
278 |
+
voice="alloy",
|
279 |
+
input=paragraph_text,
|
280 |
+
)
|
281 |
|
282 |
+
# Define the path for the audio file
|
283 |
+
audio_path = "/mnt/data/generated_audio_openai.mp3"
|
284 |
|
285 |
+
# Save the audio stream to a file
|
286 |
+
response.stream_to_file(audio_path)
|
287 |
|
288 |
+
# Return the path to the audio file along with the text
|
289 |
+
return paragraph_text, audio_path
|
290 |
|
291 |
+
except Exception as e:
|
292 |
+
print(f"An error occurred while generating TTS: {e}")
|
293 |
+
# Handle the error appropriately (e.g., return an error message or a default audio path)
|
294 |
+
return paragraph_text, None
|
295 |
|
296 |
with gr.Blocks() as demo:
|
297 |
with gr.Row():
|
requirements.txt
CHANGED
@@ -1,4 +1,2 @@
|
|
1 |
gradio
|
2 |
openai>=1.0.0
|
3 |
-
transformers
|
4 |
-
soundfile
|
|
|
1 |
gradio
|
2 |
openai>=1.0.0
|
|
|
|