|
import gradio as gr |
|
from gtts import gTTS |
|
import uuid |
|
|
|
def text_to_speech(text, lang, speed): |
|
slow = True if speed == "Slow" else False |
|
filename = f"{uuid.uuid4()}.mp3" |
|
tts = gTTS(text, lang=lang, slow=slow) |
|
tts.save(filename) |
|
return filename |
|
|
|
demo = gr.Interface( |
|
fn=text_to_speech, |
|
inputs=[ |
|
gr.Textbox(label="Enter Text"), |
|
gr.Dropdown( |
|
label="Language", |
|
choices=[ |
|
("English", "en"), |
|
("Spanish", "es"), |
|
("French", "fr"), |
|
("German", "de"), |
|
("Italian", "it"), |
|
("Japanese", "ja"), |
|
("Korean", "ko"), |
|
("Russian", "ru"), |
|
("Chinese (Simplified)", "zh-CN"), |
|
("Portuguese", "pt"), |
|
("Hindi", "hi"), |
|
("Arabic", "ar"), |
|
("Bengali", "bn"), |
|
("Dutch", "nl"), |
|
("Greek", "el"), |
|
("Hungarian", "hu"), |
|
("Indonesian", "id"), |
|
("Polish", "pl"), |
|
("Swedish", "sv"), |
|
("Thai", "th"), |
|
("Turkish", "tr"), |
|
("Vietnamese", "vi") |
|
], |
|
value="en" |
|
), |
|
gr.Dropdown( |
|
label="Speed", |
|
choices=["Normal", "Slow"], |
|
value="Normal" |
|
) |
|
], |
|
outputs=gr.Audio(label="Generated Speech", type="filepath"), |
|
title="Text to Speech Converter", |
|
description="Type something and convert it into speech using gTTS with language and speed selection.", |
|
theme="gradio/space" |
|
) |
|
|
|
demo.launch(share=True) |
|
|