File size: 588 Bytes
8a98fc0
 
 
 
 
 
 
 
 
 
7ddea1c
 
8a98fc0
 
 
 
 
 
7ddea1c
8e3b8f4
e687059
8a98fc0
 
 
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 os

os.makedirs("temp", exist_ok=True)

input_text = gr.inputs.Textbox(label="input_text")

output_audio = gr.outputs.Audio(type="filepath", label="output_audio")

def text_to_speech(text, lang="zh"):
    tts = gTTS(text, lang=lang, slow=False)
    audio_file = os.path.join("temp", "output.mp3")
    tts.save(audio_file)
    return audio_file

iface = gr.Interface(
    fn=text_to_speech,
    inputs=[input_text, gr.inputs.Dropdown([
        "en", "ja", "zh"], label="language", default="zh")],
    outputs=output_audio
)

iface.launch()