🚀 Auto-deploy: BotVPS atualizado em 28/03/2026 23:51:59
This commit is contained in:
@@ -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 <REFINED>
|
||||
texto_limpo = re.sub(r'<REFINED>.*?</REFINED>', '', texto_limpo, flags=re.DOTALL)
|
||||
|
||||
# Só remove REFINED se ele estiver presente como tag (proteção dupla)
|
||||
if "<REFINED>" in texto_limpo:
|
||||
texto_limpo = re.sub(r'<REFINED>.*?</REFINED>', '', 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)."""
|
||||
|
||||
Reference in New Issue
Block a user