首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何列出热词/唤醒词在Python snowboy模块中执行不同功能?

如何列出热词/唤醒词在Python snowboy模块中执行不同功能?
EN

Stack Overflow用户
提问于 2020-07-24 00:18:03
回答 1查看 74关注 0票数 0
代码语言:javascript
复制
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的多个实例,它工作了一小段时间,但线程在一段时间后最终为麦克风访问而争斗,它停止工作

代码语言:javascript
复制
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属性,但我在文档中找不到任何对它的引用,也找不到任何使用该属性的方式。

有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2020-07-24 00:36:26

我只是设法弄明白了,我把这篇文章贴出来,以防将来有人需要这篇文章。

代码语言:javascript
复制
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)

关键在于创建一个与唤醒单词列表长度相同的回调列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63058730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档