Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,10 +8,10 @@ os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')
|
|
8 |
|
9 |
client = OpenAI() # add api_key
|
10 |
|
11 |
-
def tts(text):
|
12 |
response = client.audio.speech.create(
|
13 |
-
model="tts-1",
|
14 |
-
voice=
|
15 |
input=text,
|
16 |
)
|
17 |
|
@@ -28,13 +28,13 @@ def tts(text):
|
|
28 |
with gr.Blocks() as demo:
|
29 |
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
30 |
with gr.Row():
|
31 |
-
|
32 |
-
|
33 |
|
34 |
text = gr.Textbox(label="Input text")
|
35 |
btn = gr.Button("Text-To-Speech")
|
36 |
output_audio = gr.Audio(label="Speech Output")
|
37 |
|
38 |
-
btn.click(fn=tts, inputs=text, outputs=output_audio, api_name="tts", concurrency_limit=None)
|
39 |
|
40 |
demo.launch()
|
|
|
8 |
|
9 |
client = OpenAI() # add api_key
|
10 |
|
11 |
+
def tts(text, model, voice):
|
12 |
response = client.audio.speech.create(
|
13 |
+
model=model, #"tts-1","tts-1-hd"
|
14 |
+
voice=voice, #'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
|
15 |
input=text,
|
16 |
)
|
17 |
|
|
|
28 |
with gr.Blocks() as demo:
|
29 |
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
30 |
with gr.Row():
|
31 |
+
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
|
32 |
+
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='alloy')
|
33 |
|
34 |
text = gr.Textbox(label="Input text")
|
35 |
btn = gr.Button("Text-To-Speech")
|
36 |
output_audio = gr.Audio(label="Speech Output")
|
37 |
|
38 |
+
btn.click(fn=tts, inputs=[text, model, voice], outputs=output_audio, api_name="tts", concurrency_limit=None)
|
39 |
|
40 |
demo.launch()
|