rany2 / edge-tts

Use Microsoft Edge's online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API key
https://pypi.org/project/edge-tts/
GNU General Public License v3.0
4.24k stars 447 forks source link

Cannot close a running event loop #132

Closed amirreza1307 closed 10 months ago

amirreza1307 commented 10 months ago

hi i use basic_generation in google colab but i get this error


RuntimeError Traceback (most recent call last) in <cell line: 22>() 24 try: ---> 25 loop.run_until_complete(amain()) 26 finally:

4 frames RuntimeError: This event loop is already running

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) /usr/lib/python3.10/asyncio/selector_events.py in close(self) 82 def close(self): 83 if self.is_running(): ---> 84 raise RuntimeError("Cannot close a running event loop") 85 if self.is_closed(): 86 return

RuntimeError: Cannot close a running event loop

why?

rany2 commented 10 months ago

You don't need to create a new event loop, instead of https://github.com/rany2/edge-tts/blob/master/examples/basic_generation.py#L23C1-L27 just do await amain()