fakevoice / app.py
seawolf2357's picture
Update app.py
02665d5
raw
history blame
1.89 kB
import gradio as gr
import requests
def generate_audio(text, voice_name):
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 = 300
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
with gr.Blocks() as demo:
gr.Markdown("### ν…μŠ€νŠΈλ₯Ό 볡제된 μŒμ„±μœΌλ‘œ λ³€ν™˜")
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()