def doConverse(self, fp, callback=None, onSay=None): try: self.interrupt() query = self.asr.transcribe(fp) utils.check_and_delete(fp) self.doResponse(query, callback, onSay) except Exception as e: logger.critical(e) utils.clean()
def converse(self, fp): """ 核心对话逻辑 """ try: self.interrupt() snowboydecoder.play_audio_file(constants.getData('beep_lo.wav')) query = self.asr.transcribe(fp) utils.check_and_delete(fp) self._doResponse(query) except Exception as e: logger.critical(e) utils.clean()
def doConverse(self, fp, callback=None, onSay=None): self.interrupt() try: query = self.asr.transcribe(fp) except Exception as e: logger.critical("ASR识别失败:{}".format(e)) utils.check_and_delete(fp) try: self.doResponse(query, callback, onSay) except Exception as e: logger.critical("回复失败:".format(e)) utils.clean()
def conversation(fp): global player, asr, ai, tts try: snowboydecoder.play_audio_file(constants.getData('beep_lo.wav')) print("converting audio to text") query = asr.transcribe(fp) utils.check_and_delete(fp) msg = ai.chat(query) voice = tts.get_speech(msg) player = Player.getPlayerByFileName(voice) player.play(voice) except ValueError as e: logger.critical(e) utils.clean()
def _signal_handler(self, signal, frame): self._interrupted = True utils.clean() self._observer.stop()
def signal_handler(signal, frame): global interrupted interrupted = True utils.clean()