From 3572eb7e63759a64f9afffe620f4fe741b391063 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Sat, 28 Mar 2026 23:51:59 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20BotVPS=20atualiza?= =?UTF-8?q?do=20em=2028/03/2026=2023:51:59?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- audio_handler.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/audio_handler.py b/audio_handler.py index d39e504..9214693 100644 --- a/audio_handler.py +++ b/audio_handler.py @@ -26,27 +26,41 @@ def transcribe_audio(file_path: str) -> str: async def text_to_speech_async(text: str) -> str: """Sintetiza texto em áudio MP3 usando Edge TTS (Versão ASYNC).""" + if not text or not text.strip(): + text = "Processado com sucesso." + # Limpeza para narração: remove tudo o que a voz tenta ler literalmente mas não deve + # Preservamos o texto original se ele já vier "limpo" (ex: vindo do main.py via refined) texto_limpo = text.replace("🤖", "").replace("🧑‍🏫", "").replace("*", "").replace("`", "") texto_limpo = texto_limpo.replace("#", "").replace("- ", " ").replace("> ", " ") - # Remove blocos - texto_limpo = re.sub(r'.*?', '', texto_limpo, flags=re.DOTALL) + + # Só remove REFINED se ele estiver presente como tag (proteção dupla) + if "" in texto_limpo: + texto_limpo = re.sub(r'.*?', '', texto_limpo, flags=re.DOTALL) + # Remove URLs e links [texto](url) texto_limpo = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', texto_limpo) - texto_limpo = re.sub(r'http[s]?://\S+', '', texto_limpo).strip() + texto_limpo = re.sub(r'http[s]?://\S+', '', texto_limpo) + # Limpeza final: remove espaços extras e garante que sobrou algo audível + texto_limpo = texto_limpo.strip() if not texto_limpo: texto_limpo = "Prompt processado." filename = f"audio_reply_{uuid.uuid4().hex[:8]}.mp3" filepath = os.path.join("/tmp", filename) - # Voz Masculina PT-BR: Donato é uma das mais realistas para comandos rápidos - voice = "pt-BR-DonatoNeural" - # Rate +35% para ser dinâmico e direto como solicitado - communicate = edge_tts.Communicate(texto_limpo, voice, rate="+35%") - await communicate.save(filepath) - return filename + try: + # Voz Masculina PT-BR: Donato + voice = "pt-BR-DonatoNeural" + communicate = edge_tts.Communicate(texto_limpo, voice, rate="+35%") + await communicate.save(filepath) + return filename + except Exception as e: + # Se falhar o TTS (ex: erro de rede ou "No audio was received"), gera um bip ou áudio simples se possível + # Aqui vamos apenas logar e relançar para o main.py tratar + print(f"[TTS ERROR] Falha ao gerar áudio para: '{texto_limpo}'. Erro: {e}") + raise def text_to_speech(text: str) -> str: """Wrapper síncrono para compatibilidade legada (CUIDADO com loops eventuais)."""