Пример #1
0
 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 ''
Пример #2
0
    def doResponse(self, query, UUID='', onSay=None):
        statistic.report(1)
        self.interrupt()
        self.appendHistory(0, query, UUID)

        if config.get('/LED/enable', False):
            LED.think()

        if onSay:
            self.onSay = onSay

        if query.strip() == '':
            self.pardon()
            return

        lastImmersiveMode = self.immersiveMode

        if not self.brain.query(query):
            # 没命中技能,使用机器人回复
            msg = self.ai.chat(query)
            self.say(msg, True, onCompleted=self.checkRestore)
        else:
            if lastImmersiveMode is not None and lastImmersiveMode != self.matchPlugin:
                time.sleep(1)
                if self.player is not None and self.player.is_playing():
                    logger.debug('等说完再checkRestore')
                    self.player.appendOnCompleted(lambda: self.checkRestore())
                else:
                    logger.debug('checkRestore')
                    self.checkRestore()

        if config.get('/LED/enable', False):
            LED.off()
Пример #3
0
 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 ""
Пример #4
0
 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)
Пример #5
0
 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)
Пример #6
0
 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")
Пример #7
0
    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)