File size: 828 Bytes
b49e49d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
from gtts import gTTS
import os

def text_to_speech(text, language='pt'):
    # Generate speech
    tts = gTTS(text=text, lang=language)
    
    # Save temporary file
    audio_path = "output.mp3"
    tts.save(audio_path)
    
    return audio_path

def process_text(text, language):
    if not text.strip():
        return None
    
    return text_to_speech(text, language)

# Interface Gradio
iface = gr.Interface(
    fn=process_text,
    inputs=[
        gr.Textbox(label="Digite o texto", lines=5),
        gr.Dropdown(choices=["pt", "en", "es", "fr"], value="pt", label="Idioma")
    ],
    outputs=gr.Audio(label="Áudio gerado", type="filepath"),
    title="Conversor de Texto para Voz",
    description="Digite um texto e converta para áudio MP3",
)

if __name__ == "__main__":
    iface.launch()