Spaces:
Running
Running
import gradio as gr | |
import requests | |
def generate_audio(text, voice_name): | |
voices = { | |
"μ°¨μΉμ": "SKwm0HLYsVDCM2ruvw2p", | |
"κΉμ μ": "YPWL3nQPzBN1XaiZF4aj", | |
"κΆμ": "4kFrgJPCTjA6DyPM5Gr5" | |
} | |
voice_id = voices[voice_name] | |
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}" | |
model_id = "eleven_multilingual_v2" | |
payload = { | |
"model_id": model_id, | |
"text": text, | |
"voice_settings": { | |
"similarity_boost": 0.75, | |
"stability": 0.5, | |
"style": 0, | |
"use_speaker_boost": True | |
} | |
} | |
headers = { | |
"Content-Type": "application/json", | |
"xi-api-key": "c5fb99a2b25402f104d246379bcf819a" | |
} | |
response = requests.post(url, json=payload, headers=headers, stream=True) | |
if response.status_code == 200: | |
chunks = [] | |
for chunk in response.iter_content(chunk_size=CHUNK_SIZE): | |
chunks.append(chunk) | |
return b''.join(chunks) | |
else: | |
raise Exception(f"μ€λ₯ λ°μ. μν μ½λ: {response.status_code}") | |
CHUNK_SIZE = 300 | |
# Gradio μΈν°νμ΄μ€ μ μ | |
with gr.Blocks() as demo: | |
gr.Markdown("### ν μ€νΈλ₯Ό 볡μ λ μμ±μΌλ‘ λ³ν") | |
gr.Markdown("AIκ° λ³΅μ ν μ λͺ μΈμ μμ±μΌλ‘, ν μ€νΈλ§ μ λ ₯νλ©΄ μμ°μ€λ½κ² ν΄λΉ μΈλ¬Όμ μμ±μΌλ‘ μμ±ν©λλ€.") | |
text_input = gr.Textbox(label="μμ±μΌλ‘ μμ±ν ν μ€νΈλ₯Ό μ λ ₯νμΈμ.(100κΈμ μ΄λ΄λ‘ μ ν)") | |
voice_choice = gr.Dropdown(choices=["μ°¨μΉμ", "κΉμ μ", "κΆμ"], label="μμ± μ ν") | |
submit_button = gr.Button("μμ±") | |
audio_output = gr.Audio(label="μμ±λ μ€λμ€") | |
submit_button.click( | |
fn=generate_audio, | |
inputs=[text_input, voice_choice], | |
outputs=audio_output | |
) | |
if __name__ == "__main__": | |
demo.launch() | |