示例#1
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))
示例#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))
示例#3
0
    def __init__(self):
        self.interrupted = False
        # 读取配置
        config_file = 'config.yaml'
        if os.path.exists(config_file) == False:
            print('【警告】配置文件不存在')
            return
        f = open('config.yaml')
        config = yaml.load(f)
        model_name = config.get('name', 'snowboy')
        if ['snowboy','alexa'].count(model_name) > 0:
            model_name = model_name + '.umdl'
        else:
            model_name = model_name + '.pmdl'

        self.model = "唤醒词/" + model_name # 使用的语音模型
        print('【唤醒词文件】' + self.model)
        if os.path.exists(self.model) == False:
            print('【警告】唤醒词文件不存在')
            return
        signal.signal(signal.SIGINT, self.signal_handler) # 捕获ctrl+c
        self.detector = snowboydecoder.HotwordDetector(self.model, sensitivity=0.5) # 设置语音模型与敏感度
        print('Listening... Press Ctrl+Z to exit')
        self.robot = Robot(config) # 创建应用模块
        self.player = Player() # 触发响应词叮咚播放
示例#4
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))
示例#5
0
    def async_listen(call):
        nonlocal detector, detected_event
        from snowboy import snowboydecoder
        detector = snowboydecoder.HotwordDetector(
            model, sensitivity=sensitivity, audio_gain=audio_gain)

        def detect():
            detector.start(lambda: detected_event.set())

        # Run detector in a separate thread
        thread = threading.Thread(target=detect, daemon=True)
        hass.states.async_set(OBJECT_SNOWBOY, STATE_LISTENING)

        thread.start()
        yield from asyncio.get_event_loop().run_in_executor(None, detected_event.wait)

        if not terminated:
            detector.terminate()
            detector = None

            thread.join()

            hass.states.async_set(OBJECT_SNOWBOY, STATE_IDLE)

            # Fire detected event
            hass.bus.async_fire(EVENT_HOTWORD_DETECTED, {
                'name': name,       # name of the component
                'model': model      # model used
            })
示例#6
0
    async def async_listen(call):
        from snowboy import snowboydecoder

        nonlocal detector
        if detector == None:
            detector = snowboydecoder.HotwordDetector(
                model,
                sensitivity=sensitivity,
                audio_gain=audio_gain,
                apply_frontend=apply_frontend)

        def detect():
            def callback():
                # Fire detected event
                _LOGGER.debug('hotword detected')
                hass.bus.async_fire(
                    EVENT_HOTWORD_DETECTED,
                    {
                        'name': name,  # name of the component
                        'model': model  # model used
                    })
                detector.terminate()

            detector.start(callback)

        # Run detector in a separate thread
        hass.states.async_set(OBJECT_SNOWBOY, STATE_LISTENING, state_attrs)

        with concurrent.futures.ThreadPoolExecutor() as pool:
            await asyncio.get_event_loop().run_in_executor(pool, detect)

        hass.states.async_set(OBJECT_SNOWBOY, STATE_IDLE, state_attrs)
示例#7
0
    def start_recognize_loop(self):
        print('Initializing...')

        # Configure Hotword detection.
        model = self.config['hotword_detector']['model']
        sensitivity = self.config['hotword_detector']['sensitivity']
        self.detector = snowboydecoder.HotwordDetector(model, sensitivity=sensitivity)

        # Configure voice recorder
        self.config['recorder']['audio'] = self.get_stream_config()
        self.voice_record = VoiceRecord(self.config['recorder'])
        if 'bg_noise_samples' in self.config['recorder']:
            self.voice_record.threshold = self.voice_record.measure_background_noise(num_samples=self.config['recorder']['bg_noise_samples'])

        # Store audio config for services.
        self.config['audio'] = self.config['recorder']['audio']
        self.config['audio']['encoding'] = self.voice_record.ENCODING

        self.create_services()

        # main loop
        print('Listening...')
        self.set_interrupted(False)
        self.detector.start(
            detected_callback=lambda: self.command_handler(),
            interrupt_check=self.interrupt_callback,
            sleep_time=0.001)

        print('Stop listening')
        self.detector.terminate()
示例#8
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()
示例#9
0
 def __init__(self):
     QtWidgets.QMainWindow.__init__(self)
     self.notice_trd = NoticeTrd(self)
     self.notice_trd.changed_notice.connect(self.on_or_off_mark)
     self.setupUi(self)
     self.move(-2, 0)
     self.verticalLayoutWidget.setGeometry(QtCore.QRect(400, 0, 400, 450))
     self.pushButton_notice.clicked.connect(self.onClickNotice)
     self.pushButton_food.clicked.connect(self.onClickFood)
     self.pushButton_weather.clicked.connect(self.onClickWeather)
     self.pushButton_shuttle.clicked.connect(self.onClickShuttle)
     self.notice_trd.start()
     self.on_or_off_mark()
     self.lat = 37.340348
     self.lon = 126.6984882
     self.detector = snowboydecoder.HotwordDetector(
         'snowboy/resources/이놈아.pmdl', sensitivity=0.6)
     self.rc = recorder.Recorder()
     self.tts = TTS()
     self.stt = STT()
     self.speaker = 'mijin'
     speech_thread = threading.Thread(target=self.speechRecogStart)
     speech_thread.daemon = True
     speech_thread.start()
     gps_thread = threading.Thread(target=self.gpsStart)
     gps_thread.daemon = True
     gps_thread.start()
示例#10
0
 def __init__(self):
     self.interrupted = False
     self.model = "snowboy.pmdl"
     signal.signal(signal.SIGINT, self.signal_handler)
     self.detector = snowboydecoder.HotwordDetector(self.model,
                                                    sensitivity=0.42)
     print('Listening... Press Ctrl+C to exit')
     self.robot = Robot()
     self.music_player = self.robot.get_music_player()
     self.player = Player()
示例#11
0
        def detect():
            detector = snowboydecoder.HotwordDetector(model,
                                                      sensitivity=sensitivity,
                                                      audio_gain=audio_gain)

            detector.start(lambda: detected_event.set(),
                           interrupt_check=interrupt_callback,
                           sleep_time=0.03)

            detector.terminate()
    def activate(self, context):
        self.stop = False
        detector = snowboydecoder.HotwordDetector(self.model, sensitivity=self.sensitivity)
        print('Say "Hey Office" to wake me up...')

        detector.start(detected_callback=self.__on_keyword_detected,
                       interrupt_check=self.__get_interrupt_check(context.is_interrupted),
                       sleep_time=self.sleep_time)
        detector.terminate()
        return TransitionContext('Listening', {})
示例#13
0
 def __init__(self):
     self.interrupted = False
     self.model = "嘿小二.pmdl"  # 使用的语音模型
     signal.signal(signal.SIGINT, self.signal_handler)  # 捕获ctrl+c
     self.detector = snowboydecoder.HotwordDetector(
         self.model, sensitivity=0.5)  # 设置语音模型与敏感度
     print('Listening... Press Ctrl+Z to exit')
     self.robot = Robot()  # 创建应用模块
     self.music_player = self.robot.get_music_player()  # 创建音乐播放模块
     self.player = Player()  # 触发响应词叮咚播放
 def detected_callback(cls):
     cls.write_pid_file()
     cls.run += 1 
     
     if cls.run >= 2:
         print "Alexa > Oui maitre ?"
         os.system("python run.py")
     
     detector = snowboydecoder.HotwordDetector(
             "models/Alexa.pmdl", sensitivity=0.48, audio_gain=1)
     detector.start(cls.detected_callback)
示例#15
0
def startKeyword():
    # Configure keyword listener
    models = ["resources/jarvis.pmdl"]
    sensitivity = [0.45] * len(models)
    detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
    callbacks = [lambda: activation_detected(detector)]
    # Start keyword listener
    print "Waiting for the keyword !"
    detector.start(detected_callback=callbacks,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.03)
示例#16
0
    def detect(self, detect_callback, interrupt_callback):
        model = "resources/Hi_Sally.pmdl"

        detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)

        print "Listening..."
        detector.start(detected_callback=detect_callback,
                       interrupt_check=interrupt_callback,
                       sleep_time=0.03)

        detector.terminate()
def detected_callback():

    launch += 1

    if launch >= 2:
        print "Jarvis > Oui maitre ?"
        system("python py_main.py")

    detector = snowboydecoder.HotwordDetector("jarviss.pmdl",
                                              sensitivity=0.37,
                                              audio_gain=1)
    detector.start(detected_callback)
示例#18
0
def main():
    signal.signal(signal.SIGINT, exit_handler)

    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.38)

    print('Listening... Press Ctrl+C to exit')

    detector.start(detected_callback=detectedCallback,
                   audio_recorder_callback=audioRecorderCallback,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.01)

    detector.terminate()
示例#19
0
文件: main.py 项目: k-aziz/Kassian
def listen_for_hotword(model):
    detector = snowboydecoder.HotwordDetector(model,
                                              sensitivity=0.5,
                                              audio_gain=1)
    print('Listening... Press Ctrl+C to exit')

    # main loop
    detector.start(detected_callback=detected_callback,
                   audio_recorder_callback=audio_recorder_callback,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.03,
                   silent_count_threshold=3,
                   save_path=CMD_AUDIO_SAVE_PATH)

    detector.terminate()
示例#20
0
 def start(self):
     # Register Ctrl-C sigint
     signal.signal(signal.SIGINT, self._signal_handler)
     # Setup snowboy
     self.detector = snowboydecoder.HotwordDetector(self.model_path,
                                                    sensitivity=[0.5])
     self.df_client = dfclient.MyDialogflowClient()
     rospy.loginfo("HOTWORD_CLIENT: Listening... Press Ctrl-C to stop.")
     while True:
         try:
             self.detector.start(detected_callback=self._snowboy_callback,
                                 interrupt_check=self._interrupt_callback,
                                 sleep_time=0.03)
         except KeyboardInterrupt:
             self.exit()
示例#21
0
def hey_krystal():
    """
    Detects "Hey Krystal"
    :return:
    """
    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    detector = snowboydecoder.HotwordDetector(AUDIO_MODEL, sensitivity=0.5)

    # main loop
    detector.start(detected_callback=snowboydecoder.play_audio_file,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.03)

    detector.terminate()
示例#22
0
 def __init__(self, model=None):
     self.wav = xv_wav()
     """ self.audio_frames 语音帧
     大概1s/12帧,安每秒的list存入dict内 {"":["","","","","","","","","","","","",""],"":["","","","","","","","","","","","",""]......} """
     self.audio_frames = {}
     """ self.audio_seconds 需要识别语音片段,每秒一个dict元素 {"":"", "":""} """
     self.audio_seconds = {}
     if model is None:
         self.model = 'snowboy'
     if self.model == 'snowboy':
         # 识别模型 snowboy
         logging.info('loaded snowboy')
         sensitivity = 0.5
         model_file = '/home/app/xiaov/snowboy/xiaov.pmdl'
         self.kws = snowboydecoder.HotwordDetector(model_file,
                                                   sensitivity=sensitivity)
示例#23
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))
示例#24
0
    def __init__(self, voice_model_file, hotword=None, sensitivity=0.5,
                 audio_gain=1.0, **kwargs):
        """ Params:
            voice_model_file -- Snowboy voice model file
            hotword  -- Name of the hotword
        """

        super().__init__(**kwargs)
        self.voice_model_file = voice_model_file
        self.hotword = hotword
        self.sensitivity = sensitivity
        self.audio_gain = audio_gain

        self.detector = snowboydecoder.HotwordDetector(
            self.voice_model_file, sensitivity=self.sensitivity,
            audio_gain=self.audio_gain)

        logging.info('Initialized Snowboy hotword detection')
示例#25
0
def main():
    print('Welcome to Voice Assistant!')
    print(' Menu ')
    print('1. Setup')
    print('2. Access Assistant')
    print('Please enter your option:')
    opt = int(input())

    if opt == 1:
        print(' Setup Menu ')
        print('1. Set Username')
        print('2. Set Assistant Name')
        print('3. Set Hotword')
        print('Please enter your option:')
        num = int(input())
        if num == 1:
            voice_assistant.speak('Welcome')
            voice_assistant_setup.setup_username()
        elif num == 2:
            voice_assistant.speak('Welcome')
            voice_assistant_setup.setup_assistant_name()
        elif num == 3:
            voice_assistant.speak('Welcome')
            voice_assistant_setup.setup_hotword()
        main()

    elif opt == 2:
        if not voice_assistant.username or voice_assistant.assistant_name:
            voice_assistant.speak('Please set up voice assistant first')
        else:
            signal.signal(signal.SIGINT, signal_handler)
            detector = snowboydecoder.HotwordDetector(model_loc,
                                                      sensitivity=0.5)
            print('Listening... Press Ctrl+C to exit')
            detector.start(detected_callback=attend_user(),
                           interrupt_check=interrupt_callback,
                           sleep_time=0.03)

            detector.terminate()
示例#26
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()
示例#27
0
    def __init__(self, strikes, cb_queue):
        """

        Args:
            strikes (deque): current attention status.
            cb_queue (queue): callback queue for passing tasks between threads.

        """
        # Logging.
        logging.basicConfig()
        self.logger = logging.getLogger("hotword")
        self.logger.setLevel(logging.DEBUG)

        self.end_detector = False
        self.strikes = strikes
        self.cb_queue = cb_queue

        self.patronum_map = Hotword.load_map()
        self.videos, self.models = self.load_videos_models()
        self.update_map()

        # Create detector.
        sensitivities = [0.5] * len(self.models)
        self.detector = sd.HotwordDetector(list(self.models),
                                      resource="snowboy/common.res",
                                      sensitivity=sensitivities,
                                      audio_gain=1)

        # Create detect thread.
        callbacks = [self.gen_callbacks(self.patronum_map[m])
                for m in list(self.models)]
        hotword_kwargs = {"detected_callback": callbacks,
                          "interrupt_check": lambda: self.end_detector,
                          "sleep_time": 0.03}
        self.detect_thread = threading.Thread(target=self.detector.start,
                                     kwargs=hotword_kwargs)
        self.detect_thread.start()
示例#28
0
def signal_handler(signal, frame):
    global interrupted
    interrupted = True


def interrupt_callback():
    global interrupted
    return interrupted


model = sys.argv[1]

# capture SIGINT signal, e.g., Ctrl+C
signal.signal(signal.SIGINT, signal_handler)

detector = snowboydecoder.HotwordDetector(model, sensitivity=0.7)
assistant = Assistant()


def snowboy_detect_controller():
    def detect_callback():
        detector.terminate()
        snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING)
        globalmodule.assistantcontroller = True
        globalmodule.hotworddetected = False
        while True:
            if globalmodule.snowboycontroller:
                globalmodule.snowboycontroller = False
                logger.info('Listening... Press Ctrl+C to exit')
                detector.start(detected_callback=detect_callback,
                               interrupt_check=interrupt_callback,
def start_recording():
    detector = snowboydecoder.HotwordDetector('hotword.pmdl', sensitivity=0.5)
    detector.start(is_recording=True)
    detector.terminate()
def wait_for_hotword():
    detector = snowboydecoder.HotwordDetector('hotword.pmdl', sensitivity=0.5)
    print('Listening... Press Ctrl+C to exit')

    detector.start()
    detector.terminate()