test111 / app.py
seawolf2357's picture
Update app.py
fc1f0e7 verified
raw
history blame contribute delete
837 Bytes
import gradio as gr
from gtts import gTTS
import tempfile
import os
def text_to_speech(text, language):
tts = gTTS(text, lang=language)
# μž„μ‹œ νŒŒμΌμ„ μƒμ„±ν•˜κ³  MP3 νŒŒμΌμ„ μ €μž₯ν•©λ‹ˆλ‹€.
temp_file = tempfile.NamedTemporaryFile(suffix='.mp3', delete=False)
tts.save(temp_file.name)
temp_file.close() # νŒŒμΌμ„ λ‹«κ³  μ‹€μ œ 경둜λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
return temp_file.name
# Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
iface = gr.Interface(
fn=text_to_speech,
inputs=[
gr.Textbox(lines=2, placeholder="μŒμ„± 생성을 μœ„ν•΄ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”"),
gr.Dropdown(label="μ–Έμ–΄ 선택", choices=["en", "es", "de", "fr", "ko"], value="ko")
],
outputs=gr.Audio(type="filepath", label="μƒμ„±λœ μŒμ„±"),
)
# μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.
iface.launch()