Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gtts import gTTS
|
3 |
+
import os
|
4 |
+
|
5 |
+
def text_to_speech(text, language='pt'):
|
6 |
+
# Generate speech
|
7 |
+
tts = gTTS(text=text, lang=language)
|
8 |
+
|
9 |
+
# Save temporary file
|
10 |
+
audio_path = "output.mp3"
|
11 |
+
tts.save(audio_path)
|
12 |
+
|
13 |
+
return audio_path
|
14 |
+
|
15 |
+
def process_text(text, language):
|
16 |
+
if not text.strip():
|
17 |
+
return None
|
18 |
+
|
19 |
+
return text_to_speech(text, language)
|
20 |
+
|
21 |
+
# Interface Gradio
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=process_text,
|
24 |
+
inputs=[
|
25 |
+
gr.Textbox(label="Digite o texto", lines=5),
|
26 |
+
gr.Dropdown(choices=["pt", "en", "es", "fr"], value="pt", label="Idioma")
|
27 |
+
],
|
28 |
+
outputs=gr.Audio(label="Áudio gerado", type="filepath"),
|
29 |
+
title="Conversor de Texto para Voz",
|
30 |
+
description="Digite um texto e converta para áudio MP3",
|
31 |
+
)
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
iface.launch()
|