taiage/bloque1/md_a_audio_con_edge.py

29 lines
896 B
Python

import asyncio
import edge_tts
import re
from pathlib import Path
def limpiar_markdown(texto):
texto = re.sub(r'```.*?```', ' [código] ', texto, flags=re.DOTALL)
texto = re.sub(r'\|.*?\|', '', texto)
texto = re.sub(r'[#*_~`>]', '', texto)
return ' '.join(texto.split())
async def convertir_archivo(path_md):
audio_output = path_md.with_suffix('.mp3')
texto = path_md.read_text(encoding="utf-8")
texto_limpio = limpiar_markdown(texto)
# La voz "Alvaro" es muy natural para estudiar
comunicar = edge_tts.Communicate(texto_limpio, "es-ES-AlvaroNeural")
await comunicar.save(audio_output)
print(f"✅ Generado: {audio_output}")
async def main():
archivos = sorted(Path('.').glob('tema*.md'))
for md in archivos:
print(f"Procesando: {md.name}...")
await convertir_archivo(md)
if __name__ == "__main__":
asyncio.run(main())