Spaces:
Running
Running
import gradio as gr | |
import requests | |
def generate_audio(text, voice_name): | |
# ๊ฐ ์์ฑ ์ต์ ์ ๋ํ ๊ธฐ๋ณธ ํ ์คํธ ์์ | |
default_examples = { | |
"๋จ์ฑAI": "์๋ ํ์ธ์, ๋จ์ฑ AI ํ์ค ์์ฑ์ ๋๋ค.", | |
"์ฌ์ฑAI": "์๋ ํ์ธ์, ์ฌ์ฑ AI ํ์ค ์์ฑ์ ๋๋ค.", | |
"ํธ๋ผํ": "Make, America, Great, Again! , ๋ค์, ์๋ํ, ๋ฏธ๊ตญ์, ๋ง๋ญ์๋ค!", | |
"์ฐจ์น์": "์๋ ํ์ธ์, ์ํด ๋ณต ๋ง์ด ๋ฐ์ผ์๊ธธ ๊ธฐ์ํฉ๋๋ค.", | |
"๊น์ ์": "์๋ ํ์ธ์, ์ํด ๋ณต ๋ง์ด ๋ฐ์ผ์๊ธธ ๊ธฐ์ํฉ๋๋ค.", | |
"๋ ธ๋ฌดํ": "์๋ ํ์ธ์, ์ํด ๋ณต ๋ง์ด ๋ฐ์ผ์๊ธธ ๊ธฐ์ํฉ๋๋ค.", | |
"๊ณฝ์ฒ ์ฉ": "๋งํฌ ๋๊ต๋ ๋ฌด๋์ก๋~? , ๋ด ์์ ์ ๋ฌป๊ณ , ๋๋ธ๋ก ๊ฐ~!", | |
"๊ถ์": "์๋ ํ์ธ์, ๋ฏธ๋ฅต์ ๊ฐ๋ฅด์นจ์, ์ด๋ง๋ ๋ฐ๋ฉํ์ด๋๋ผ.", | |
"์ค์์ด": "์๋ ํ์ธ์, ์ํด ๋ณต ๋ง์ด ๋ฐ์ผ์๊ธธ ๊ธฐ์ํฉ๋๋ค." | |
} | |
MAX_CHARS = 100 | |
if not text: | |
text = default_examples[voice_name] # ์ฌ์ฉ์ ์ ๋ ฅ์ด ์์ผ๋ฉด ๊ธฐ๋ณธ ์์ ์ฌ์ฉ | |
elif len(text) > MAX_CHARS: | |
text = text[:MAX_CHARS] # ์ต๋ ๊ธ์์๋ก ํ ์คํธ ์๋ฅด๊ธฐ | |
voices = { | |
"๋จ์ฑAI": "6uQD2RqeSgIey9LVBafG", | |
"์ฌ์ฑAI": "jeuEgCxtyEYkC3zsQODy", | |
"ํธ๋ผํ": "nP4xQZkEwzlvgutdc3xM", | |
"์ฐจ์น์": "SKwm0HLYsVDCM2ruvw2p", | |
"๊น์ ์": "YPWL3nQPzBN1XaiZF4aj", | |
"๋ ธ๋ฌดํ": "6JdivX36i1eJ3LqLmvwH", | |
"๊ณฝ์ฒ ์ฉ": "xareIzgmUtHZat32qZIN", | |
"๊ถ์": "4kFrgJPCTjA6DyPM5Gr5", | |
"์ค์์ด": "Qrf03Q67kRgpFlj9fto3" | |
} | |
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("FakeVoice: AI๊ฐ ๋ณต์ ํ ์ ๋ช ์ธ์ ์์ฑ์ผ๋ก, ํ ์คํธ๋ง ์ ๋ ฅํ๋ฉด ์์ฐ์ค๋ฝ๊ฒ ํด๋น ์ธ๋ฌผ์ ์์ฑ์ผ๋ก ์์ฑํฉ๋๋ค.") | |
gr.Markdown("์ง๊ธ ์ปค๋ฎค๋ํฐ์ ์ฐธ์ฌํ์๋ฉด ๋์ฑ ๋ง์ ์ ๋ณด์ ๋ค์ํ ๊ธฐํ๋ฅผ ์ป์ผ์ค ๊ฒ์ ๋๋ค. ์ปค๋ฎค๋ํฐ ์ฐธ์ฌ ๋งํฌ https://open.kakao.com/o/gE6hK9Vf ") | |
gr.Markdown("์์ฑ์ ๋จผ์ ์ ํํ ํ ์ํ์๋ ํ ์คํธ๋ฅผ ์ ๋ ฅํ์ธ์. ํ ์คํธ๋ฅผ ์ ๋ ฅํ์ง ์๊ณ ์์ฑ์ ๋๋ฅด๋ฉด ์์ ๋์ฌ๊ฐ ์์ฑ๋ฉ๋๋ค.") | |
gr.Markdown("์์ฑ๋ ์ค๋์ค๋ฅผ ๋ค์ด๋ก๋ ํ ์ ์์ต๋๋ค. ๋ค์ด๋ก๋ ๋ฐ์ผ์ ํ ๋ค์ด๋ก๋ ๋ฐ์ ํ์ผ์ ํ์ฅ์๋ฅผ mp3๋ก ๋ณ๊ฒฝํ์๋ฉด ๋ฉ๋๋ค. ") | |
voice_choice = gr.Dropdown(choices=["๋จ์ฑAI", "์ฌ์ฑAI", "ํธ๋ผํ", "์ฐจ์น์", "๊น์ ์", "๋ ธ๋ฌดํ", "๊ณฝ์ฒ ์ฉ", "๊ถ์", "์ค์์ด"], label="์์ฑ ์ ํ") | |
text_input = gr.Textbox(label="์์ฑ์ผ๋ก ์์ฑํ ํ ์คํธ๋ฅผ ์ ๋ ฅํ์ธ์.(100๊ธ์ ์ด๋ด ์ ํ ์ค์ ๋์ด, ์ด๊ณผ์ ์์ฑ ์์ฑ์ด ์ ํ๋ฉ๋๋ค.)") | |
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() |