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 = """ .gradio-container { background: white !important; } .label { color: black !important; } .gr-box { background: white !important; color: black !important; } .gr-input { color: black !important; } .gr-button { background: #2196F3 !important; color: white !important; } .gr-form { background: white !important; color: black !important; } .footer { text-align: center; margin-top: 50px; color: #666 !important; font-size: 0.9em; } """ with gr.Blocks(theme=gr.themes.Light(), css=css) as iface: with gr.Column(): 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") audio_output = gr.Audio(label="Áudio Gerado", interactive=True) gr.Markdown( """ """ ) convert_button.click(process_tts, inputs=[text_input, voice], outputs=[audio_output]) iface.launch(show_api=False)