import gradio as gr import edge_tts import asyncio import os # Vozes disponíveis VOICES = { "Antonio": "pt-BR-AntonioNeural", "Andrew (Multilingual)": "en-US-AndrewMultilingualNeural", "Brian (Multilingual)": "en-US-BrianMultilingualNeural", "Francisca": "pt-BR-FranciscaNeural", "Thalita": "pt-BR-ThalitaNeural", "Ava (Multilingual)": "en-US-AvaMultilingualNeural", "Emma (Multilingual)": "en-US-EmmaMultilingualNeural" } async def text_to_speech(text, voice): voice_key = VOICES[voice] output_file = f"output_{hash(text)}.mp3" communicate = edge_tts.Communicate(text, voice_key) await communicate.save(output_file) return output_file async def process_tts(text, voice): return await text_to_speech(text, voice) css = """ body { background-color: #f0f0f0; font-family: 'Arial', sans-serif; } .container { max-width: 800px; margin: 0 auto; padding: 20px; background-color: white; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } h1 { color: #2c3e50; text-align: center; margin-bottom: 30px; } .footer { text-align: center; margin-top: 50px; color: #7f8c8d; font-size: 0.9em; } """ with gr.Blocks(css=css) as iface: with gr.Column(elem_classes="container"): gr.Markdown("# TSM - Texto em Voz") gr.Markdown("Converta texto em fala usando vozes em português e multilíngues.") with gr.Row(): with gr.Column(scale=2): text_input = gr.Textbox( label="Digite o texto para converter em fala", placeholder="Escreva seu texto aqui...", lines=5 ) with gr.Column(scale=1): voice = gr.Radio( choices=list(VOICES.keys()), label="Escolha a voz", value="Francisca" ) convert_button = gr.Button("Converter para Áudio", variant="primary") audio_output = gr.Audio(label="Áudio Gerado") gr.Markdown( """
""", elem_classes="footer" ) convert_button.click(process_tts, inputs=[text_input, voice], outputs=[audio_output]) iface.launch(show_api=False)