简体   繁体   English

Python:让虚拟助手在说“嘿助手”后再次聆听

[英]Python: Make Virtual Assistant Listen Again After Saying “Hey Assistant”

Using the code below the virtual assistant will listen for commands but after saying "try again" it will stop to listen.使用下面的代码,虚拟助手将监听命令,但在说“再试一次”后它将停止监听。 How do I make it listen again using the wake command "hey assistant".如何使用唤醒命令“嘿助手”让它再次收听。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM