Spaces:
Build error
Build error
Commit
ยท
bc18a34
1
Parent(s):
0d2047f
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
else:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# Create a temp file to save the audio
|
26 |
-
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
27 |
-
temp_file.write(response.content)
|
28 |
-
|
29 |
-
# Get the file path of the temp file
|
30 |
-
temp_file_path = temp_file.name
|
31 |
-
|
32 |
-
return temp_file_path
|
33 |
-
|
34 |
-
|
35 |
-
with gr.Blocks() as demo:
|
36 |
-
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
37 |
-
#gr.HTML("You can also access the Streaming demo for OpenAI TTS by clicking this <a href='https://huggingface.co/spaces/ysharma/OpenAI_TTS_Streaming'>Gradio demo link</a>")
|
38 |
-
with gr.Row(variant='panel'):
|
39 |
-
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS demo')
|
40 |
-
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
|
41 |
-
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='alloy')
|
42 |
-
|
43 |
-
text = gr.Textbox(label="Input text", placeholder="Enter your text and then click on the 'Text-To-Speech' button, or simply press the Enter key.")
|
44 |
-
btn = gr.Button("Text-To-Speech")
|
45 |
-
output_audio = gr.Audio(label="Speech Output")
|
46 |
-
|
47 |
-
text.submit(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
|
48 |
-
btn.click(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
|
49 |
-
|
50 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def generate_audio(text):
|
5 |
+
voice_id = 'SKwm0HLYsVDCM2ruvw2p'
|
6 |
+
url = "https://api.elevenlabs.io/v1/text-to-speech/" + voice_id
|
7 |
+
model_id = "eleven_multilingual_v2"
|
8 |
+
payload = {
|
9 |
+
"model_id": model_id,
|
10 |
+
"text": text,
|
11 |
+
"voice_settings": {
|
12 |
+
"similarity_boost": 0.75,
|
13 |
+
"stability": 0.5,
|
14 |
+
"style": 0,
|
15 |
+
"use_speaker_boost": True
|
16 |
+
}
|
17 |
+
}
|
18 |
+
headers = {
|
19 |
+
"Content-Type": "application/json",
|
20 |
+
"xi-api-key": "c5fb99a2b25402f104d246379bcf819a"
|
21 |
+
}
|
22 |
+
|
23 |
+
response = requests.post(url, json=payload, headers=headers, stream=True)
|
24 |
+
|
25 |
+
if response.status_code == 200:
|
26 |
+
return response.content
|
27 |
else:
|
28 |
+
raise Exception(f"์ค๋ฅ ๋ฐ์. ์ํ ์ฝ๋: {response.status_code}")
|
29 |
+
|
30 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=generate_audio,
|
33 |
+
inputs=gr.inputs.Textbox(label="๋ณํํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์."),
|
34 |
+
outputs=gr.outputs.Audio(label="์์ฑ๋ ์ค๋์ค"),
|
35 |
+
title="ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ",
|
36 |
+
description="Eleven Labs API๋ฅผ ์ฌ์ฉํ์ฌ ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํํฉ๋๋ค."
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|