0
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()

^^^^ 我尝试在不同的线程中运行多个雪人实例,这些线程总是在监听,它工作了一点,但是一段时间后线程最终会争夺麦克风访问权限并且它停止工作

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)

^^^^ 我尝试将不同的唤醒词文件放在一个列表中然后运行它。它可以工作,但现在我无法弄清楚它如何为每个唤醒词执行单独的函数。

我还注意到了一个detector.num_hotwords 属性,但是我在文档中找不到对它的任何引用或任何使用该属性的方式。

有什么建议么?

4

1 回答 1

0

我只是设法弄清楚,我将其发布以防将来有人需要它。

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)

关键在于使回调列表的长度与唤醒词列表的长度相同。

于 2020-07-23T16:36:25.587 回答