如何使用python使用多个唤醒词(snowboy)?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用python使用多个唤醒词(snowboy)?相关的知识,希望对你有一定的参考价值。
我正在建立一个个人语音助手,我想让我的AI用唤醒词来听命令(我不知道这是一个好主意,所以如果不建议我,因为SpeechRecogniton需要互联网及其支持,有点沉重,使AI响应更加缓慢...但是当我输入多个唤醒词并执行他时,它无法识别任何命令...
import datetime
import pyttsx3 # pip install pyttsx3
import os
import sys
import re
import snowboy.snowboydecoder as snowboydecoder
engine = pyttsx3.init()
voices = engine.getProperty('voices')
# for voice in voices:
# print(voice.id)
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def Greetings():
speak ("Hi Sir")
def How_are_you_doing():
speak ("I'm very good, Sir. And You?")
def wake_word():
print ("Hello_word")
detector=snowboydecoder.HotwordDetector("Hey_Bold.pmdl",sensitivity=0.5,audio_gain=1)
detector.start(Greetings)
def how_you_doing():
print ("how_you_doing_word")
detector_how = snowboydecoder.HotwordDetector("How_you_doing.pmdl", sensitivity=0.5, audio_gain=1)
detector_how.start(How_are_you_doing)
欢迎使用任何设备!
答案
这对在raspberry pi 4上运行的我很有效,最近创建的声音-
import locale
import logging
import signal
from aiy.assistant.grpc import AssistantServiceClientWithLed
from aiy.board import Board
import mod.snowboydecoder as snowboydecoder
models = ['/home/pi/snowboy/resources/wake_word1.umdl',
'/home/pi/snowboy/resources/wake_word12.umdl']
def main():
logging.basicConfig(level=logging.DEBUG)
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(0))
detector = snowboydecoder.HotwordDetector(models, sensitivity=0.5)
with Board() as board:
assistant = AssistantServiceClientWithLed(
board=board,
volume_percentage=100,
language_code=locale.getdefaultlocale())
while True:
logging.info('say any of your pre-defined hotwords to start the assisteant')
detector.start()
logging.info('assistant is now listening :)')
assistant.conversation()
if __name__ == '__main__':
main()
以上是关于如何使用python使用多个唤醒词(snowboy)?的主要内容,如果未能解决你的问题,请参考以下文章