javipalanca / spade

Smart Python Agent Development Environment
MIT License
257 stars 98 forks source link

How to add custom method calls to event loop? #62

Closed ccarstens closed 5 years ago

ccarstens commented 5 years ago

Description

I want to use a speech synthesis package called pyttsx3 which offers its own event loop for the execution of the synthesis. When using their event loop the voice output blocks everything else until I stop their event loop, which comes with a 1200ms delay.

Pyttsx3 als offers to use a custom event loop as described here.

Where would I call engine.iterate()?

Can I add Tasks or method calls to Spade's event loop?

Thank you for helping me! <3

javipalanca commented 5 years ago

agent.loop is the event loop of all the agents in the same process. You can access it also through the agent container:

container = Container()  # anywhere, since it is a singleton
container.loop
ccarstens commented 5 years ago

Thank you, Javi! Since the modules I'm using aren't implementing asyncio I ended up putting all the IO in it's own process while using the agent's run() method to monitor a queue with user responses.