from snowboy import snowboydecoder
import threading
def hello():
print('Hello')
def greeting():
print('Im doing good.')
def det_hi():
detector = snowboydecoder.HotwordDetector('Hi.pmdl', sensitivity=0.5, audio_gain=1)
detector.start(hello)
def det_greeting():
d2 = snowboydecoder.HotwordDetector('HowAreYou.pmdl', sensitivity=0.5, audio_gain=1)
d2.start(greeting)
thread1 = threading.Thread(target=det_hi)
thread2 = threading.Thread(target=det_greeting)
thread1.start()
thread2.start()
^^^^ I tried running multiple instances of snowboy in different threads that are always listening, and it works for a little bit, but the threads end up fighting over mic access after a while and it stops working
from snowboy import snowboydecoder
import threading
wake_words = ['Hi.pmdl', 'HowAreYou.pmdl']
def hello():
print('Hello')
def greeting():
print('Im doing good.')
detector = snowboydecoder.HotwordDetector(wake_words, sensitivity=0.5, audio_gain=1)
detector.start(hello)
^^^^ I tried putting the different wake word files in a list and running it then. It works, but now i cant figure out how have it execute a separate function for each wake word.
I also noticed a detector.num_hotwords attribute, but i couldnt find any reference to it in the docs or any way to use that attribute.
Any suggestions?
I just managed to figure it out, I'm posting this in case anyone needs this in the future.
The key was in making a list of callbacks the same length as the list of wake words.