Fix support for Python 3.10

Signed-off-by: rany2 <rany2@riseup.net>
This commit is contained in:
rany2 2023-06-02 20:03:37 +03:00
parent 0094e3b952
commit ca6e7b0669
5 changed files with 20 additions and 15 deletions

View File

@ -20,7 +20,8 @@ VOICE = "en-GB-SoniaNeural"
OUTPUT_FILE = "test.mp3" OUTPUT_FILE = "test.mp3"
async def _main() -> None: async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE) communicate = edge_tts.Communicate(TEXT, VOICE)
with open(OUTPUT_FILE, "wb") as file: with open(OUTPUT_FILE, "wb") as file:
async for chunk in communicate.stream(): async for chunk in communicate.stream():
@ -31,8 +32,8 @@ async def _main() -> None:
if __name__ == "__main__": if __name__ == "__main__":
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop_policy().get_event_loop()
try: try:
loop.run_until_complete(_main()) loop.run_until_complete(amain())
finally: finally:
loop.close() loop.close()

View File

@ -13,14 +13,15 @@ VOICE = "en-GB-SoniaNeural"
OUTPUT_FILE = "test.mp3" OUTPUT_FILE = "test.mp3"
async def _main() -> None: async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE) communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE) await communicate.save(OUTPUT_FILE)
if __name__ == "__main__": if __name__ == "__main__":
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop_policy().get_event_loop()
try: try:
loop.run_until_complete(_main()) loop.run_until_complete(amain())
finally: finally:
loop.close() loop.close()

View File

@ -14,7 +14,8 @@ TEXT = "Hoy es un buen día."
OUTPUT_FILE = "spanish.mp3" OUTPUT_FILE = "spanish.mp3"
async def _main() -> None: async def amain() -> None:
"""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
@ -25,8 +26,8 @@ async def _main() -> None:
if __name__ == "__main__": if __name__ == "__main__":
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop_policy().get_event_loop()
try: try:
loop.run_until_complete(_main()) loop.run_until_complete(amain())
finally: finally:
loop.close() loop.close()

View File

@ -17,7 +17,8 @@ OUTPUT_FILE = "test.mp3"
WEBVTT_FILE = "test.vtt" WEBVTT_FILE = "test.vtt"
async def _main() -> None: async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE) communicate = edge_tts.Communicate(TEXT, VOICE)
submaker = edge_tts.SubMaker() submaker = edge_tts.SubMaker()
with open(OUTPUT_FILE, "wb") as file: with open(OUTPUT_FILE, "wb") as file:
@ -32,8 +33,8 @@ async def _main() -> None:
if __name__ == "__main__": if __name__ == "__main__":
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop_policy().get_event_loop()
try: try:
loop.run_until_complete(_main()) loop.run_until_complete(amain())
finally: finally:
loop.close() loop.close()

View File

@ -77,7 +77,8 @@ async def _run_tts(args: Any) -> None:
sub_file.write(subs.generate_subs(args.words_in_cue)) sub_file.write(subs.generate_subs(args.words_in_cue))
async def _async_main() -> None: async def amain() -> None:
"""Async main function"""
parser = argparse.ArgumentParser(description="Microsoft Edge TTS") parser = argparse.ArgumentParser(description="Microsoft Edge TTS")
group = parser.add_mutually_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-t", "--text", help="what TTS will say") group.add_argument("-t", "--text", help="what TTS will say")
@ -131,9 +132,9 @@ async def _async_main() -> None:
def main() -> None: def main() -> None:
"""Run the main function using asyncio.""" """Run the main function using asyncio."""
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop_policy().get_event_loop()
try: try:
loop.run_until_complete(_async_main()) loop.run_until_complete(amain())
finally: finally:
loop.close() loop.close()