properties.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Lab-Assistant 作者: SPARC-Auburn 项目源码 文件源码
def processcommand(self, usermsg, source):
        """
        Processes command from user and deals with wake word detection
        Returns True if Response was when assistant is awoken
        :param usermsg: The message that the user inputted
        :param source: Microphone audio source
        """
        print ("< " + usermsg)
        wake_words = ["hey", "ok", "okay", "yo", "you", "hi"]
        awake = False
        for word in wake_words:
            if self.userCommand == word + " " + self.name:
                awake = True
        if awake:
            self.playsound("start.mp3")
            self.speak("Yes?")
            print ("\tWaiting for command..")
            response_heard = False
            while not response_heard:
                print ("\tThreshold: " + str(self.r.energy_threshold))
                print ("\tWaiting for command...")
                try:
                    audio = self.r.listen(source, timeout=5)
                    print("...")
                    self.playsound("end.mp3")
                    try:
                        self.userCommand = self.r.recognize_google(audio)
                        self.userCommand = self.userCommand.lower()
                        response_heard = True
                        print ("< " + self.userCommand)
                    except sr.UnknownValueError:
                        print("\tUnknown Value from Google, or nothing heard")
                    except sr.RequestError as e:
                        print("\tCould not request results from Google Speech Recognition service; {0}".format(e))
                    except Exception as e:
                        print (str(e))
                except Exception:
                    print ("\tHeard nothing")
                    pass
            return True
        else:
            for word in wake_words:
                if self.userCommand.__contains__(word + " " + self.name):
                    print ("\tGetting command..")
                    self.userCommand = self.userCommand.split(word + " " + self.name + " ")[1]
                    return True
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号