Spaces:
Runtime error
Runtime error
import gradio as gr | |
import requests | |
def generate_audio(text, voice_name): | |
MAX_CHARS = 100 | |
# ์ ๋ ฅ๋ ํ ์คํธ ๊ธธ์ด ๊ฒ์ฆ | |
if len(text) > MAX_CHARS: | |
text = text[:MAX_CHARS] # ์ต๋ ๊ธ์์๋ก ํ ์คํธ ์๋ฅด๊ธฐ | |
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 = 1024 | |
# Gradio ์ธํฐํ์ด์ค ์ ์ | |
with gr.Blocks() as demo: | |
gr.Markdown("๋ฐ๋ผ ๋ณด์ด์ค: AI ์์ฑ ๋ณต์ , ์์ฑ ์๋ฎฌ๋ ์ด์ ") | |
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() | |