fakevoice / app.py
seawolf2357's picture
Update app.py
6085495
raw
history blame
2.13 kB
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()