Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files
1mp3.mp3
ADDED
|
Binary file (40.3 kB). View file
|
|
|
3mp3.mp3
ADDED
|
Binary file (61 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tempfile
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
first_alert = "1mp3.mp3"
|
| 5 |
+
next_alert = "3mp3.mp3"
|
| 6 |
+
|
| 7 |
+
def Txt_To_Speech(api_key, model, voice,speed,text):
|
| 8 |
+
if api_key == '':
|
| 9 |
+
output= first_alert
|
| 10 |
+
else:
|
| 11 |
+
try:
|
| 12 |
+
client = OpenAI(api_key=api_key)
|
| 13 |
+
response = client.audio.speech.create(
|
| 14 |
+
model=model,
|
| 15 |
+
voice=voice,
|
| 16 |
+
speed=speed,
|
| 17 |
+
input=text
|
| 18 |
+
)
|
| 19 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
| 20 |
+
temp_file.write(response.content)
|
| 21 |
+
|
| 22 |
+
temp_file_path = temp_file.name
|
| 23 |
+
output = temp_file_path
|
| 24 |
+
except :
|
| 25 |
+
output = next_alert
|
| 26 |
+
return output
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# TTS Text To Speech using OpenAI ")
|
| 31 |
+
|
| 32 |
+
text1 = gr.Textbox(type = 'password',label="Enter your API-Key", placeholder="API-Key", lines=1)
|
| 33 |
+
model = gr.Dropdown(choices=["tts-1", "tts-1-hd"], label="Model", value="tts-1")
|
| 34 |
+
voice = gr.Dropdown(choices=["alloy", "echo", "fable", "onyx", "nova", "shimmer"], label="Voice Options",
|
| 35 |
+
value="alloy")
|
| 36 |
+
speed = gr.Slider(minimum=0.25, maximum=4.0, value=1.0, step=0.01, label="Speed")
|
| 37 |
+
|
| 38 |
+
text = gr.Textbox(label="Please Enter text",placeholder="Enter your Input")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
gr.Interface(
|
| 45 |
+
Txt_To_Speech,
|
| 46 |
+
[
|
| 47 |
+
text1,model,voice,speed,text
|
| 48 |
+
],
|
| 49 |
+
outputs=gr.Audio(label="Speech Output")
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
openai
|