Skip to content

Instantly share code, notes, and snippets.

@shuantsu
Last active February 28, 2025 15:37
Show Gist options
  • Save shuantsu/1f669fedf880f542a8a6d6c0ae928f6c to your computer and use it in GitHub Desktop.
Save shuantsu/1f669fedf880f542a8a6d6c0ae928f6c to your computer and use it in GitHub Desktop.
Sintetizador de voz da microsoft edge em script Python
'''
exemplo de uso: python app.py artigo.txt
lembre de instalar esses módulos:
asyncio
edge_tts
para isso rode os comandos:
pip insall asyncio
pip insall edge_tts
'''
import asyncio
import sys
import edge_tts
VOICES = [ 'pt-BR-AntonioNeural', 'pt-BR-FranciscaNeural']
'''
O índice 0 é voz PT-BR masculina.
O índice 1 é voz PT-BR feminina.
Você pode mudar essa lista colocando outras vozes...
https://gist.github.com/BettyJJ/17cbaa1de96235a7f5773b8690a20462
'''
fn = sys.argv[1]
TEXT = open(fn,'r',encoding='utf8').read()
VOICE = VOICES[0]
OUTPUT_FILE = f"{fn.split('\\')[-1]}".replace('txt','mp3')
async def amain():
communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE)
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment