|
from gtts import gTTS |
|
import gradio as gr |
|
import os |
|
|
|
|
|
def text_to_speech(text, language="hr"): |
|
|
|
tts = gTTS(text=text, lang=language, slow=False) |
|
|
|
|
|
audio_file = "output.mp3" |
|
tts.save(audio_file) |
|
|
|
return audio_file |
|
|
|
|
|
def tts_demo(text, language): |
|
|
|
audio_file = text_to_speech(text, language) |
|
|
|
|
|
return audio_file |
|
|
|
|
|
inputs = [ |
|
gr.Textbox(label="Enter Text", placeholder="Type something here..."), |
|
gr.Dropdown(label="Language", choices=["en", "es", "fr", "de", "hr"], value="hr") |
|
] |
|
outputs = gr.Audio(label="Generated Audio", type="filepath") |
|
|
|
|
|
iface = gr.Interface( |
|
fn=tts_demo, |
|
inputs=inputs, |
|
outputs=outputs, |
|
title="Text-to-Speech Demo", |
|
description="Enter text and select a language to generate and play audio." |
|
) |
|
|
|
|
|
iface.launch() |