ysharma HF staff commited on
Commit
7ebcd98
1 Parent(s): 660df4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
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="alloy",
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
- dd1 = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model')
32
- dd2 = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options')
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()