Spaces:
Running
Running
File size: 2,691 Bytes
aa95dd5 bc18a34 a2087de a160271 a2087de c77f602 a2087de c77f602 a2087de bc18a34 699ea5d 02665d5 7d0efdb bc18a34 699ea5d 02665d5 bc18a34 2796462 150e1e4 a56731b 65dcd62 2d9d2d5 9529845 2796462 65dcd62 2796462 a2087de 2796462 bc18a34 b3012ac bc18a34 a2087de |
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 |
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 = {
"๋จ์ฑAI": "6uQD2RqeSgIey9LVBafG",
"์ฌ์ฑAI": "jeuEgCxtyEYkC3zsQODy",
"์ฐจ์น์": "SKwm0HLYsVDCM2ruvw2p",
"๊น์ ์": "YPWL3nQPzBN1XaiZF4aj",
"๋
ธ๋ฌดํ": "6JdivX36i1eJ3LqLmvwH",
"๊ถ์": "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("์์ฑ๋ ์ค๋์ค๋ฅผ ๋ค์ด๋ก๋ ํ ์ ์์ต๋๋ค. ๋ค์ด๋ก๋ ๋ฐ์ผ์ ํ ๋ค์ด๋ก๋ ๋ฐ์ ํ์ผ์ ํ์ฅ์๋ฅผ mp3๋ก ๋ณ๊ฒฝํ์๋ฉด ๋ฉ๋๋ค. ")
text_input = gr.Textbox(label="์์ฑ์ผ๋ก ์์ฑํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์.(100๊ธ์ ์ด๋ด ์ ํ ์ค์ ๋์ด, ์ด๊ณผ์ ์์ฑ ์์ฑ์ด ์ ํ๋ฉ๋๋ค.)")
voice_choice = gr.Dropdown(choices=["๋จ์ฑAI", "์ฌ์ฑAI", "์ฐจ์น์", "๊น์ ์", "๋
ธ๋ฌดํ", "๊ถ์", "์ค์์ด"], 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()
|