Last active
February 28, 2025 15:37
-
-
Save shuantsu/1f669fedf880f542a8a6d6c0ae928f6c to your computer and use it in GitHub Desktop.
Sintetizador de voz da microsoft edge em script Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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