File size: 837 Bytes
2d71bf6
50bc6ed
15164d0
 
0669fa1
9a50ea8
50bc6ed
9a50ea8
 
 
 
 
0669fa1
a46b0f6
0669fa1
50bc6ed
 
9a50ea8
fc1f0e7
50bc6ed
9a50ea8
0669fa1
 
a46b0f6
b30eb63
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
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()