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?