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()^我尝试在总是在监听的不同线程中运行snowboy的多个实例,它工作了一小段时间,但线程在一段时间后最终为麦克风访问而争斗,它停止工作
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)^我尝试将不同的wake word文件放在列表中,然后运行它。它可以工作,但现在我不知道如何让它为每个唤醒单词执行一个单独的函数。
我还注意到了一个detector.num_hotwords属性,但我在文档中找不到任何对它的引用,也找不到任何使用该属性的方式。
有什么建议吗?
发布于 2020-07-24 00:36:26
我只是设法弄明白了,我把这篇文章贴出来,以防将来有人需要这篇文章。
from snowboy import snowboydecoder
import threading
def hello():
print('Hello')
def greeting():
print('Im doing good.')
wake_words = ['Hi.pmdl', 'HowAreYou.pmdl']
callbacks = [hello, greetings] # For some reason does work if you include the () on the function
detector = snowboydecoder.HotwordDetector(wake_words, sensitivity=0.5, audio_gain=1)
detector.start(detected_callback=callbacks)关键在于创建一个与唤醒单词列表长度相同的回调列表。
https://stackoverflow.com/questions/63058730
复制相似问题