0

我正在构建一个个人语音助手,我想让我的 AI 通过唤醒词来听命令(我不知道这是否是个好主意,所以如果不是建议我),因为 SpeechRecogniton 需要互联网并且它有点重并使AI响应更慢...但是当我输入超过1个唤醒词并执行他时,它无法识别任何命令...

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)

欢迎任何设备!

4

1 回答 1

0

为了收听一些唤醒词,只需将唤醒词模型路径列表传递给 HotwordDetector(见下文)。

下面是收听连接到谷歌助手的一些唤醒词的工作示例(使用来自https://github.com/google/aiyprojects-raspbian/releases/tag/v20191113的 AIY VOICE IMAGE 运行 rpi 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()
于 2019-11-22T23:28:51.430 回答