0

使用下面的代码,虚拟助手将监听命令,但在说“再试一次”后它将停止监听。如何使用唤醒命令“嘿助手”让它再次收听。

def myCommand():

    r = sr.Recognizer()                                                                                   
    with sr.Microphone() as source:                                                                       
        print("Listening...")
        r.pause_threshold =  1
        text = r.listen(source)
    try:
        query = r.recognize_google(text, language='en')
        print('User: ' + query + '\n')

    except sr.UnknownValueError:
        speak('Sorry sir! I didn\'t get that.')
        query = str(input('Try again'))




    return query
4

1 回答 1

3
# you can call it using this...
hotword = 'hey assistant'
while 1:
    result = myCommand()
    if hotword in result:
        #here what you want to do...
        #respose_of_assistant()
于 2020-04-14T16:22:58.890 回答