Skip to content

Commit

Permalink
Fix support for Python 3.10
Browse files Browse the repository at this point in the history
Signed-off-by: rany2 <[email protected]>
  • Loading branch information
rany2 committed Jun 2, 2023
1 parent 0094e3b commit ca6e7b0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
7 changes: 4 additions & 3 deletions examples/basic_audio_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
OUTPUT_FILE = "test.mp3"


async def _main() -> None:
async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE)
with open(OUTPUT_FILE, "wb") as file:
async for chunk in communicate.stream():
Expand All @@ -31,8 +32,8 @@ async def _main() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(_main())
loop.run_until_complete(amain())
finally:
loop.close()
7 changes: 4 additions & 3 deletions examples/basic_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
OUTPUT_FILE = "test.mp3"


async def _main() -> None:
async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE)


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(_main())
loop.run_until_complete(amain())
finally:
loop.close()
7 changes: 4 additions & 3 deletions examples/dynamic_voice_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
OUTPUT_FILE = "spanish.mp3"


async def _main() -> None:
async def amain() -> None:
"""Main function"""
voices = await VoicesManager.create()
voice = voices.find(Gender="Male", Language="es")
# Also supports Locales
Expand All @@ -25,8 +26,8 @@ async def _main() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(_main())
loop.run_until_complete(amain())
finally:
loop.close()
7 changes: 4 additions & 3 deletions examples/streaming_with_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
WEBVTT_FILE = "test.vtt"


async def _main() -> None:
async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE)
submaker = edge_tts.SubMaker()
with open(OUTPUT_FILE, "wb") as file:
Expand All @@ -32,8 +33,8 @@ async def _main() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(_main())
loop.run_until_complete(amain())
finally:
loop.close()
7 changes: 4 additions & 3 deletions src/edge_tts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ async def _run_tts(args: Any) -> None:
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")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-t", "--text", help="what TTS will say")
Expand Down Expand Up @@ -131,9 +132,9 @@ async def _async_main() -> None:

def main() -> None:
"""Run the main function using asyncio."""
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(_async_main())
loop.run_until_complete(amain())
finally:
loop.close()

Expand Down

0 comments on commit ca6e7b0

Please sign in to comment.