From e82a2d1d86365ac594a0c4a6fe552426a66055a6 Mon Sep 17 00:00:00 2001 From: Jack Cheng Date: Mon, 8 Apr 2024 09:57:20 +0800 Subject: [PATCH] Simplify asyncio main loop setup --- examples/basic_audio_streaming.py | 6 +----- examples/basic_generation.py | 6 +----- examples/dynamic_voice_selection.py | 6 +----- examples/streaming_with_subtitles.py | 6 +----- src/edge_tts/util.py | 6 +----- 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/examples/basic_audio_streaming.py b/examples/basic_audio_streaming.py index 0aadc66..503d76d 100644 --- a/examples/basic_audio_streaming.py +++ b/examples/basic_audio_streaming.py @@ -32,8 +32,4 @@ async def amain() -> None: if __name__ == "__main__": - loop = asyncio.get_event_loop_policy().get_event_loop() - try: - loop.run_until_complete(amain()) - finally: - loop.close() + asyncio.run(amain()) diff --git a/examples/basic_generation.py b/examples/basic_generation.py index 6e102ee..24d391a 100644 --- a/examples/basic_generation.py +++ b/examples/basic_generation.py @@ -20,8 +20,4 @@ async def amain() -> None: if __name__ == "__main__": - loop = asyncio.get_event_loop_policy().get_event_loop() - try: - loop.run_until_complete(amain()) - finally: - loop.close() + asyncio.run(amain()) diff --git a/examples/dynamic_voice_selection.py b/examples/dynamic_voice_selection.py index e1e1701..2b05395 100644 --- a/examples/dynamic_voice_selection.py +++ b/examples/dynamic_voice_selection.py @@ -26,8 +26,4 @@ async def amain() -> None: if __name__ == "__main__": - loop = asyncio.get_event_loop_policy().get_event_loop() - try: - loop.run_until_complete(amain()) - finally: - loop.close() + asyncio.run(amain()) diff --git a/examples/streaming_with_subtitles.py b/examples/streaming_with_subtitles.py index e562d9e..cccc904 100644 --- a/examples/streaming_with_subtitles.py +++ b/examples/streaming_with_subtitles.py @@ -33,8 +33,4 @@ async def amain() -> None: if __name__ == "__main__": - loop = asyncio.get_event_loop_policy().get_event_loop() - try: - loop.run_until_complete(amain()) - finally: - loop.close() + asyncio.run(amain()) diff --git a/src/edge_tts/util.py b/src/edge_tts/util.py index f1c25b4..7f674e5 100644 --- a/src/edge_tts/util.py +++ b/src/edge_tts/util.py @@ -133,11 +133,7 @@ async def amain() -> None: def main() -> None: """Run the main function using asyncio.""" - loop = asyncio.get_event_loop_policy().get_event_loop() - try: - loop.run_until_complete(amain()) - finally: - loop.close() + asyncio.run(amain()) if __name__ == "__main__":