28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
|
|
import asyncio
|
||
|
|
import os
|
||
|
|
import edge_tts
|
||
|
|
|
||
|
|
# 1. Define the phrase, output path, and target Castellano voice
|
||
|
|
SPANISH_TEXT = "¡Buenos días! ¿Cómo estás? Bienvenido a tu curso de español."
|
||
|
|
OUTPUT_FILE = "media/buenos_dias_castellano-Female.mp3"
|
||
|
|
#VOICE = "es-ES-AlvaroNeural" # Swap to "es-ES-ElviraNeural" if you prefer a female tone
|
||
|
|
VOICE = "es-ES-ElviraNeural" # Swap to "es-ES-ElviraNeural" if you prefer a female tone
|
||
|
|
|
||
|
|
async def generate_castilian_audio():
|
||
|
|
# Ensure our target media folder exists locally
|
||
|
|
os.makedirs(os.path.dirname(OUTPUT_FILE), exist_ok=True)
|
||
|
|
|
||
|
|
print(f"🔄 Synthesizing text using Castilian voice: {VOICE}...")
|
||
|
|
|
||
|
|
# 2. Configure the Communicate engine
|
||
|
|
communicate = edge_tts.Communicate(SPANISH_TEXT, VOICE)
|
||
|
|
|
||
|
|
# 3. Stream and write the data packets to disk
|
||
|
|
await communicate.save(OUTPUT_FILE)
|
||
|
|
|
||
|
|
print(f"✨ Success! MP3 file exported safely to: {OUTPUT_FILE}")
|
||
|
|
print(f"📂 File size: {os.path.getsize(OUTPUT_FILE)} bytes")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
# Run the async loop loop natively
|
||
|
|
asyncio.run(generate_castilian_audio())
|