properties.py 文件源码

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

项目:Lab-Assistant 作者: SPARC-Auburn 项目源码 文件源码
def listen(self):
        """Listens to response from microphone and converts to text"""
        self.userCommand = ""
        with sr.Microphone(device_index=self.mic, chunk_size=1024, sample_rate=48000) as source:
            print ("\tThreshold: " + str(self.r.energy_threshold))
            print ("\tWaiting for words...")
            try:
                audio = self.r.listen(source, timeout=5)
                # self.playSound("end.mp3")
                try:
                    self.userCommand = self.r.recognize_google(audio)
                    self.userCommand = self.userCommand.lower()
                    if not self.processcommand(self.userCommand, source):
                        return False
                    else:
                        return True
                except sr.UnknownValueError:
                    print ("\t...")
                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 ("\tNo audio heard")
                pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号