How to use multiple wake words (snowboy) using python?

931 Views Asked by At

I'm building a personal voice assistant, and I wanna to make my AI listen to commands by wake words (I don't know if it is a good idea, so if not advice me) since SpeechRecogniton requires internet and its a little heavy and makes the AI response more slowly... But when I put more than 1 wake word and execute him it doesn't recognise any command...

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)

Any devices are welcome!

1

There are 1 best solutions below

0
On

in order to listen to a number of wake words, simply pass a list of wake words model paths to HotwordDetector (see below).

below is a working example of listening to a number of wakewords connected to google's assistant (running of rpi 4 with AIY VOICE IMAGE from https://github.com/google/aiyprojects-raspbian/releases/tag/v20191113)

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