Spaces:
Running
Running
Updating functions to intake voice as a paremeter
Browse files
app.py
CHANGED
@@ -8,13 +8,13 @@ os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')
|
|
8 |
|
9 |
client = OpenAI() # add api_key
|
10 |
|
11 |
-
|
|
|
12 |
response = client.audio.speech.create(
|
13 |
-
model=
|
14 |
-
voice=
|
15 |
input=text,
|
16 |
)
|
17 |
-
|
18 |
# Create a temp file to save the audio
|
19 |
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
20 |
temp_file.write(response.content)
|
@@ -28,13 +28,14 @@ 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
|
|
|
39 |
|
40 |
-
demo.launch()
|
|
|
8 |
|
9 |
client = OpenAI() # add api_key
|
10 |
|
11 |
+
# Updated tts function now takes model and voice as parameters
|
12 |
+
def tts(text, model, voice): # <-- Change here: added model and voice as parameters
|
13 |
response = client.audio.speech.create(
|
14 |
+
model=model, # <-- Change here: using the model parameter
|
15 |
+
voice=voice, # <-- Change here: using the voice parameter
|
16 |
input=text,
|
17 |
)
|
|
|
18 |
# Create a temp file to save the audio
|
19 |
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
20 |
temp_file.write(response.content)
|
|
|
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 |
+
# Updated btn.click to pass model and voice parameters to the tts function
|
39 |
+
btn.click(fn=tts, inputs=[text, dd1, dd2], outputs=output_audio, api_name="tts") # <-- Change here: added dd1 and dd2 to inputs
|
40 |
|
41 |
+
demo.launch()
|