Continue plugin execution while indigo server speaking

Posted on
Sun Mar 13, 2016 5:00 pm
krissh offline
Posts: 105
Joined: Nov 18, 2012
Location: Norway

Continue plugin execution while indigo server speaking

Hi,

What I'm trying to achieve for my plugin is the following:

- Plugin calls for a speech notification and then the plugin continues execution without waiting for the speak to finish
- The speech "call" should do the following:
1. Execute an action group and wait for it to finish
2. Speak the specified text and wait for it to finish
3. Execute an action group

I have been trying both with the thread and threading module without success. What I have presently is this:

Within the plugin action the following:
Code: Select all
         self.debugLog(u'Speaking notification, starting separate thread for speech')
         #thread.start_new_thread( self.speakNotification, (notificationText, catProps[u'beforeSpeakActionGroup'], catProps[u'afterSpeakActionGroup'] ) )
         speakThread = speakNotificationThread(notificationText, catProps[u'beforeSpeakActionGroup'], catProps[u'afterSpeakActionGroup'] )
         speakThread.start()
         self.threads.append(speakThread)
         #speakThread.join()
         self.debugLog(u'Thread for speech notification started')


Outside the plugin class the following:

Code: Select all
class speakNotificationThread (threading.Thread):
    def __init__(self, notification, beforeAG, afterAG):
        threading.Thread.__init__(self)
        self.notification = notification
        self.beforeAG = beforeAG
        self.afterAG = afterAG
        #self.nplugin = nplugin
    def run(self):
        indigo.server.log( "Starting speak thread--")
        speakNotification(self.notification, self.beforeAG, self.afterAG)
        indigo.server.log( "Exiting speak thread--")
       
def speakNotification(notification, beforeAG, afterAG):
   if len(beforeAG) > 0:
      indigo.actionGroup.execute(int(beforeAG))
   indigo.server.speak(notification, waitUntilDone=True)
   if len(afterAG) > 0:
      indigo.actionGroup.execute(int(afterAG))


No matter what I do the plugin execution waits for the thread to finish before it continues. Is it possible to achieve this somehow?

Posted on
Mon Mar 14, 2016 9:41 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Continue plugin execution while indigo server speaking

Why not just:

Code: Select all
indigo.server.speak(notification, waitUntilDone=False)


instead of all the thread?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Mar 14, 2016 9:44 am
krissh offline
Posts: 105
Joined: Nov 18, 2012
Location: Norway

Re: Continue plugin execution while indigo server speaking

Because I want to execute the last action group when the speak is finished. Is it a way to accomplish this?

Posted on
Mon Mar 14, 2016 11:54 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Continue plugin execution while indigo server speaking

Just do your action group executions that need to happen while the speech is going on first, then do the speech and wait. The time between the action group executions and the speech starting will be minimal.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Mar 14, 2016 12:23 pm
krissh offline
Posts: 105
Joined: Nov 18, 2012
Location: Norway

Re: Continue plugin execution while indigo server speaking

Thanks Jay,

I guess that'll be the solution.
I tried different threading options, but no matter what I do it seems the action execution is paused as long as the thread is running.

There is quite a lot of things happening in my action, so I wanted to start the speak as early as possible and continue running other things, in order to minimize the wait for the speak. Nevertheless, it is probably less than a second for complex situations and normally tenths of a second, so it should be OK.

I thought of starting an external script using IndigoPluginHost, but as the IndigoPluginHost takes a moment to set up and connect the delay is probably longer this way.

Thanks again.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests