SpaceGhost's picture
Update app.py
366e06d verified
import gradio as gr
from gtts import gTTS
import os
def generate_speech(text, language):
tts = gTTS(text=text, lang=language)
tts.save("output.mp3")
return "output.mp3"
language_options = {
"American English": 'en',
"Korean": 'ko',
"Mandarin(Chinese mainland)": 'zh-CN',
"Japanese": 'jp',
"Spanish": 'es',
"French": 'fr',
"Português": 'pt'
# Add more languages as needed
}
iface = gr.Interface(
fn=generate_speech,
inputs=[
gr.Textbox(lines=2, placeholder="Enter text here..."),
gr.Radio(choices=list(language_options.keys()), label="Language")
],
outputs="audio",
title="Text-to-Speech Converter",
description="Enter text and choose a language to convert text to speech."
)
def process_text_and_language(text, language):
language_code = language_options[language]
return generate_speech(text, language_code)
iface = gr.Interface(
fn=process_text_and_language,
inputs=[
gr.Textbox(lines=2, placeholder="Enter text here..."),
gr.Radio(choices=list(language_options.keys()), label="Language")
],
outputs="audio",
title="Text-to-Speech Converter",
description="Enter text and choose a language to convert text to speech."
)
iface.launch()