2023-01-04 22:04:22 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""
|
|
|
|
Example of dynamic voice selection using VoicesManager.
|
|
|
|
"""
|
|
|
|
|
2023-01-04 19:51:30 +00:00
|
|
|
import asyncio
|
2023-01-04 22:04:22 +00:00
|
|
|
import random
|
|
|
|
|
2023-01-04 19:51:30 +00:00
|
|
|
import edge_tts
|
|
|
|
from edge_tts import VoicesManager
|
2023-01-04 22:04:22 +00:00
|
|
|
|
2023-01-05 05:48:40 +00:00
|
|
|
TEXT = "Hoy es un buen día."
|
|
|
|
OUTPUT_FILE = "spanish.mp3"
|
2023-01-04 19:51:30 +00:00
|
|
|
|
2023-01-05 05:48:40 +00:00
|
|
|
|
|
|
|
async def _main() -> None:
|
2023-01-04 19:51:30 +00:00
|
|
|
voices = await VoicesManager.create()
|
2023-01-04 22:04:22 +00:00
|
|
|
voice = voices.find(Gender="Male", Language="es")
|
2023-01-04 19:51:30 +00:00
|
|
|
# Also supports Locales
|
|
|
|
# voice = voices.find(Gender="Female", Locale="es-AR")
|
|
|
|
|
2023-01-05 05:48:40 +00:00
|
|
|
communicate = edge_tts.Communicate(TEXT, random.choice(voice)["Name"])
|
2023-01-04 22:07:01 +00:00
|
|
|
await communicate.save(OUTPUT_FILE)
|
2023-01-04 19:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-04-26 21:38:47 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
try:
|
|
|
|
loop.run_until_complete(_main())
|
|
|
|
finally:
|
|
|
|
loop.close()
|