Spaces:
Running
Running
File size: 3,981 Bytes
aa95dd5 bc18a34 a2087de 189c85a f441359 189c85a a160271 189c85a a160271 a2087de c77f602 d8bb1cb a2087de c77f602 5a96413 c77f602 a2087de bc18a34 699ea5d 02665d5 7d0efdb bc18a34 699ea5d 02665d5 bc18a34 2796462 150e1e4 a56731b 189c85a 8b95e13 2d9d2d5 2796462 65dcd62 2796462 a2087de 2796462 bc18a34 b3012ac bc18a34 189c85a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
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() |