gtts / app.py
tangjicheng
modified: app.py
8e3b8f4
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()