Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+
5
+ # Set your OpenAI API key
6
+ openai.api_key = os.getenv("OPENAI_API_KEY") # Read from environment variable
7
+
8
+ def text_to_speech(text):
9
+ response = openai.audio.speech.create(
10
+ model="tts-1", # or "tts-1-hd"
11
+ voice="nova", # options: "nova", "shimmer", etc
12
+ input=text
13
+ )
14
+ filename = "output.mp3"
15
+ with open(filename, "wb") as f:
16
+ f.write(response.content)
17
+ return filename
18
+
19
+ iface = gr.Interface(
20
+ fn=text_to_speech,
21
+ inputs=gr.Textbox(lines=2, placeholder="Enter text to convert to speech..."),
22
+ outputs=gr.Audio(type="filepath"),
23
+ title="Text to Speech with OpenAI",
24
+ description="Enter text and get the spoken audio!",
25
+ )
26
+
27
+ iface.launch()