update dynamic_voice_selection.py for new API
This commit is contained in:
@@ -1,26 +1,28 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Example of dynamic voice selection using VoicesManager.
|
||||||
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import edge_tts
|
|
||||||
from edge_tts import VoicesManager
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
import edge_tts
|
||||||
|
from edge_tts import VoicesManager
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""
|
|
||||||
Main function
|
|
||||||
"""
|
|
||||||
voices = await VoicesManager.create()
|
voices = await VoicesManager.create()
|
||||||
voice = voices.find(Gender="Male", Language="es")
|
voice = voices.find(Gender="Male", Language="es")
|
||||||
# Also supports Locales
|
# Also supports Locales
|
||||||
# voice = voices.find(Gender="Female", Locale="es-AR")
|
# voice = voices.find(Gender="Female", Locale="es-AR")
|
||||||
VOICE = random.choice(voice)["ShortName"]
|
VOICE = random.choice(voice)["ShortName"]
|
||||||
TEXT = "Hoy es un buen día."
|
TEXT = "Hoy es un buen día."
|
||||||
OUTPUT_FILE = "spanish.mp3"
|
OUTPUT_FILE = "spanish.mp3"
|
||||||
|
|
||||||
communicate = edge_tts.Communicate()
|
communicate = edge_tts.Communicate(TEXT, VOICE)
|
||||||
|
communicate.save(OUTPUT_FILE)
|
||||||
|
|
||||||
with open(OUTPUT_FILE, "wb") as f:
|
|
||||||
async for i in communicate.run(TEXT, voice=VOICE):
|
|
||||||
if i[2] is not None:
|
|
||||||
f.write(i[2])
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.get_event_loop().run_until_complete(main())
|
asyncio.get_event_loop().run_until_complete(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user