def activeListen(self, silent=False): """ 主动问一个问题(适用于多轮对话) """ if config.get('/LED/enable', False): LED.wakeup() logger.debug('activeListen') try: if not silent: #time.sleep(1) Player.play(constants.getData('beep_hi.wav')) listener = snowboydecoder.ActiveListener([ constants.getHotwordModel(config.get('hotword', 'wukong.pmdl')) ]) voice = listener.listen( silent_count_threshold=config.get('silent_threshold', 15), recording_timeout=config.get('recording_timeout', 5) * 4) if not silent: Player.play(constants.getData('beep_lo.wav')) if voice: query = self.asr.transcribe(voice) utils.check_and_delete(voice) return query return '' except Exception as e: logger.error(e) return ''
def activeListen(self, silent=False): """主动问一个问题(适用于多轮对话)""" if config.get("/LED/enable", False): LED.wakeup() logger.debug("activeListen") try: if not silent: Player.play(constants.getData("beep_hi.wav")) listener = snowboydecoder.ActiveListener([ constants.getHotwordModel(config.get("hotword", "wukong.pmdl")) ]) voice = listener.listen( silent_count_threshold=config.get("silent_threshold", 15), recording_timeout=config.get("recording_timeout", 5) * 4, ) if not silent: Player.play(constants.getData("beep_lo.wav")) if voice: query = self.asr.transcribe(voice) utils.check_and_delete(voice) return query return "" except Exception as e: logger.error("主动聆听失败".format(e)) return ""
def play(self, src, delete=False, onCompleted=None, volume=1): """ 播放一个音频 """ if config.get('/LED/enable', False): LED.wakeup() logger.debug('activeSpeak') if self.player: self.interrupt() self.player = Player.SoxPlayer() self.player.play(src, delete=delete, onCompleted=onCompleted)
def _detected_callback(self): def start_record(): logger.info('开始录音') self._conversation.isRecording = True; if not utils.is_proper_time(): logger.warning('勿扰模式开启中') return if self._conversation.isRecording: logger.warning('正在录音中,跳过') return self._conversation.interrupt() if config.get('/LED/enable', False): LED.wakeup() Player.play(constants.getData('beep_hi.wav'), onCompleted=start_record, wait=True)
def _detected_callback(self): def start_record(): logger.info('开始录音') print('开始录音') self._conversation.isRecording = True; if not utils.is_proper_time(): logger.warning('勿扰模式开启中') return if self._conversation.isRecording: logger.warning('正在录音中,跳过') return self._conversation.interrupt() if config.get('/LED/enable', False): LED.wakeup() Player.play(constants.getData(random.choice(self._response_wav)), onCompleted=start_record, wait=True) with open("../communication/InPut.txt", "w") as file_writer: file_writer.write("true")
def _detected_callback(self): def start_record(): logger.info("开始录音") self._conversation.isRecording = True utils.setRecordable(True) if not utils.is_proper_time(): logger.warning("勿扰模式开启中") return if self._conversation.isRecording: logger.warning("正在录音中,跳过") return self._conversation.interrupt() if config.get("/LED/enable", False): LED.wakeup() utils.setRecordable(False) Player.play(constants.getData("beep_hi.wav"), onCompleted=start_record, wait=True)