Esempio n. 1
0
 def initDetector(self):
     if self.detector is not None:
         self.detector.terminate()
     if config.get('/do_not_bother/hotword_switch', False):
         models = [
             constants.getHotwordModel(config.get('hotword', 'wukong.pmdl')),
             constants.getHotwordModel(utils.get_do_not_bother_on_hotword()),
             constants.getHotwordModel(utils.get_do_not_bother_off_hotword())
         ]
     else:
         models = constants.getHotwordModel(config.get('hotword', 'wukong.pmdl'))
     self.detector = snowboydecoder.HotwordDetector(models, sensitivity=config.get('sensitivity', 0.5))
     # main loop
     try:
         if config.get('/do_not_bother/hotword_switch', False):
             callbacks = [self._detected_callback,
                          self._do_not_bother_on_callback,
                          self._do_not_bother_off_callback]
         else:
             callbacks = self._detected_callback
         self.detector.start(detected_callback=callbacks,
                             audio_recorder_callback=self._conversation.converse,
                             interrupt_check=self._interrupt_callback,
                             silent_count_threshold=config.get('silent_threshold', 15),
                             recording_timeout=config.get('recording_timeout', 5) * 4,
                             sleep_time=0.03)
         self.detector.terminate()
     except Exception as e:
         logger.critical('离线唤醒机制初始化失败:{}'.format(e))
Esempio n. 2
0
 def initDetector(self):
     """初始化唤醒探测器"""
     if self.detector is not None:
         self.detector.terminate()
     models = [
         constants.getHotwordModel(config.get('hotword', 'wukong.pmdl')),
         constants.getHotwordModel(utils.get_do_not_bother_on_hotword()),
         constants.getHotwordModel(utils.get_do_not_bother_off_hotword())
     ]
     #唤醒词检测函数,调整sensitivity参数可修改唤醒词检测的准确性
     self.detector = snowboydecoder.HotwordDetector(models,
                                                    sensitivity=config.get(
                                                        'sensitivity', 0.5))
     # main loop
     try:
         #唤醒参数设置及成功唤醒后的回调设置
         self.detector.start(
             detected_callback=[
                 self._detected_callback, self._do_not_bother_on_callback,
                 self._do_not_bother_off_callback
             ],
             audio_recorder_callback=self._conversation.converse,
             interrupt_check=self._interrupt_callback,
             silent_count_threshold=config.get('silent_threshold', 15),
             recording_timeout=config.get('recording_timeout', 5) * 4,
             sleep_time=0.03)
         #释放资源
         self.detector.terminate()
     except Exception as e:
         logger.critical('离线唤醒机制初始化失败:{}'.format(e))
Esempio n. 3
0
    def run(self):
        self.init()
        models = [
            constants.getHotwordModel(config.get('hotword', 'wukong.pmdl')),
            constants.getHotwordModel(utils.get_do_not_bother_on_hotword()),
            constants.getHotwordModel(utils.get_do_not_bother_off_hotword())
        ]

        # capture SIGINT signal, e.g., Ctrl+C
        signal.signal(signal.SIGINT, self._signal_handler)
        detector = snowboydecoder.HotwordDetector(models,
                                                  sensitivity=config.get(
                                                      'sensitivity', 0.5))
        print('Listening... Press Ctrl+C to exit')

        # site
        server.run()

        # main loop
        detector.start(detected_callback=[
            self._detected_callback, self._do_not_bother_on_callback,
            self._do_not_bother_off_callback
        ],
                       audio_recorder_callback=self._conversation.converse,
                       interrupt_check=self._interrupt_callback,
                       silent_count_threshold=5,
                       sleep_time=0.03)
        detector.terminate()
Esempio n. 4
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 ''
Esempio n. 5
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 ""
Esempio n. 6
0
    def initDetector(self):
        if self.detector is not None:
            self.detector.terminate()

        models = [
            constants.getHotwordModel(config.get('hotword', 'xiaofeng.pmdl'))
        ]

        # gql 检测唤醒词
        self.detector = snowboydecoder.HotwordDetector(models,
                                                       sensitivity=config.get(
                                                           'sensitivity', 0.5))

        # main loop
        try:
            callbacks = self._detected_callback

            self.detector.start(
                detected_callback=callbacks,
                audio_recorder_callback=self._conversation.converse,
                interrupt_check=self._interrupt_callback,
                silent_count_threshold=config.get('silent_threshold', 15),
                recording_timeout=config.get('recording_timeout', 5) * 4,
                sleep_time=0.03)
            self.detector.terminate()
        except Exception as e:
            print("error")
            logger.critical('离线唤醒机制初始化失败:{}'.format(e))
Esempio n. 7
0
    def initDetector(self):
        if self.detector is not None:
            self.detector.terminate()
        models = config.get('hotword', 'wukong.pmdl').split(',')
        for i in range(0, len(models)):
            models[i] = constants.getHotwordModel(models[i])

        if config.get('/do_not_bother/hotword_switch', False):
            models.append(
                constants.getHotwordModel(
                    utils.get_do_not_bother_on_hotword()))
            models.append(
                constants.getHotwordModel(
                    utils.get_do_not_bother_off_hotword()))

        logger.debug('init models:' + str(len(models)))
        logger.debug(models)
        self.detector = snowboydecoder.HotwordDetector(models,
                                                       sensitivity=config.get(
                                                           'sensitivity', 0.5))
        logger.debug(self.detector)
        # main loop
        try:
            callbacks = []
            for i in range(
                    0, len(config.get('hotword', 'wukong.pmdl').split(','))):
                callbacks.append(self._detected_callback)
            if config.get('/do_not_bother/hotword_switch', False):
                callbacks = [
                    self._detected_callback, self._do_not_bother_on_callback,
                    self._do_not_bother_off_callback
                ]
            #else:
            #    callbacks = self._detected_callback
            logger.debug('wukong callbacks:')
            logger.debug(callbacks)
            self.detector.start(
                detected_callback=callbacks,
                audio_recorder_callback=self._conversation.converse,
                interrupt_check=self._interrupt_callback,
                silent_count_threshold=config.get('silent_threshold', 15),
                recording_timeout=config.get('recording_timeout', 5) * 4,
                sleep_time=0.03)
            self.detector.terminate()
        except Exception as e:
            logger.critical('离线唤醒机制初始化失败:{}'.format(e))
 def activeListen(self):
     """ 主动问一个问题(适用于多轮对话) """
     snowboydecoder.play_audio_file(constants.getData('beep_hi.wav'))
     listener = snowboydecoder.ActiveListener([constants.getHotwordModel(config.get('hotword', 'wukong.pmdl'))])
     voice = listener.listen()
     snowboydecoder.play_audio_file(constants.getData('beep_lo.wav'))
     query = self.asr.transcribe(voice)
     utils.check_and_delete(voice)
     return query
Esempio n. 9
0
def main():
    init()
    logger.debug('config: {}'.format(config.getConfig()))
    models = [
        constants.getHotwordModel(config.get('hotword', 'wukong.pmdl')),
        constants.getHotwordModel(utils.get_do_not_bother_hotword())
    ]
    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)
    detector = snowboydecoder.HotwordDetector(models,
                                              sensitivity=config.get(
                                                  'sensitivity', 0.5))
    print('Listening... Press Ctrl+C to exit')

    # main loop
    detector.start(
        detected_callback=[detected_callback, do_not_bother_callback],
        audio_recorder_callback=conversation,
        interrupt_check=interrupt_callback,
        silent_count_threshold=5,
        sleep_time=0.03)
    detector.terminate()
Esempio n. 10
0
 def activeListen(self):
     """ 主动问一个问题(适用于多轮对话) """
     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)
     Player.play(constants.getData('beep_lo.wav'))
     query = self.asr.transcribe(voice)
     utils.check_and_delete(voice)
     return query