🚀 Auto-deploy: BotVPS atualizado em 24/03/2026 11:57:55
This commit is contained in:
@@ -24,16 +24,8 @@ def transcribe_audio(file_path: str) -> str:
|
||||
if os.path.exists(temp_wav):
|
||||
os.remove(temp_wav)
|
||||
|
||||
async def _edge_tts_gen(text: str, filepath: str):
|
||||
"""Gera áudio usando Microsoft Edge TTS (Gratuito e Neural)."""
|
||||
# Voz Masculina PT-BR: Antonio ou Donato
|
||||
# Rate +20% para ser mais rápido conforme pedido
|
||||
voice = "pt-BR-AntonioNeural"
|
||||
communicate = edge_tts.Communicate(text, voice, rate="+20%")
|
||||
await communicate.save(filepath)
|
||||
|
||||
def text_to_speech(text: str) -> str:
|
||||
"""Sintetiza texto em áudio MP3 usando Edge TTS (Voz Masculina Rápida)."""
|
||||
async def text_to_speech_async(text: str) -> str:
|
||||
"""Sintetiza texto em áudio MP3 usando Edge TTS (Versão ASYNC)."""
|
||||
# Limpeza para narração
|
||||
texto_limpo = text.replace("🤖", "").replace("🧑🏫", "").replace("*", "").replace("`", "")
|
||||
texto_limpo = re.sub(r'<REFINED>.*?</REFINED>', '', texto_limpo, flags=re.DOTALL).strip()
|
||||
@@ -44,13 +36,20 @@ def text_to_speech(text: str) -> str:
|
||||
filename = f"audio_reply_{uuid.uuid4().hex[:8]}.mp3"
|
||||
filepath = os.path.join("/tmp", filename)
|
||||
|
||||
# Voz Masculina PT-BR: Antonio
|
||||
# Rate +20% para ser mais rápido
|
||||
voice = "pt-BR-AntonioNeural"
|
||||
communicate = edge_tts.Communicate(texto_limpo, voice, rate="+20%")
|
||||
await communicate.save(filepath)
|
||||
return filename
|
||||
|
||||
def text_to_speech(text: str) -> str:
|
||||
"""Wrapper síncrono para compatibilidade legada (CUIDADO com loops eventuais)."""
|
||||
try:
|
||||
# Edge TTS é async, precisamos rodar no loop
|
||||
asyncio.run(_edge_tts_gen(texto_limpo, filepath))
|
||||
return filename
|
||||
except Exception as e:
|
||||
print(f"[VOICE] Erro Edge TTS: {e}. Criando arquivo mudo ou ignorando.")
|
||||
# Cria um arquivo vazio para não quebrar o retorno
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(b"")
|
||||
return filename
|
||||
# Se já houver um loop rodando (ex: Telegram), isso vai falhar
|
||||
return asyncio.run(text_to_speech_async(text))
|
||||
except RuntimeError:
|
||||
# Fallback: se houver loop, tenta rodar de forma síncrona ou retorna erro
|
||||
# No nosso caso, o bot_logic e main.py devem usar a versão ASYNC diretamente
|
||||
print("[VOICE] Erro: text_to_speech (sync) chamado dentro de um event loop.")
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user