def pause_trigger_process(self): """ The trigger has been awaken, we pause it :return: """ logger.debug("[Order] Entering state: %s" % self.state) self.trigger_instance.pause() # if here, then the trigger has been called and paused HookManager.on_triggered() self.next_state()
def waiting_for_trigger_callback_thread(self): """ Method to print in debug that the main process is waiting for a trigger detection """ logger.debug("[Order] Entering state: %s" % self.state) if self.settings.options.deaf: # the user asked to deaf inside the deaf neuron Utils.print_info("Kalliope is deaf") self.trigger_instance.pause() else: Utils.print_info("Waiting for trigger detection") # this loop is used to keep the main thread alive while not self.trigger_callback_called: sleep(0.1) # if here, then the trigger has been called HookManager.on_triggered() self.next_state()
def run(self): """ Start the voice detector. For every `sleep_time` second it checks the audio buffer for triggering keywords. If detected, then call corresponding function in `detected_callback`, which can be a single function (single model) or a list of callback functions (multiple models). Every loop it also calls `interrupt_check` -- if it returns True, then breaks from the loop and return. :param detected_callback: a function or list of functions. The number of items must match the number of models in `decoder_model`. :param interrupt_check: a function that returns True if the main loop needs to stop. :param float sleep_time: how much time in second every loop waits. :param audio_recorder_callback: if specified, this will be called after a keyword has been spoken and after the phrase immediately after the keyword has been recorded. The function will be passed the name of the file where the phrase was recorded. :param silent_count_threshold: indicates how long silence must be heard to mark the end of a phrase that is being recorded. :param recording_timeout: limits the maximum length of a recording. :return: None """ if self.interrupt_check(): logger.debug("detect voice return") return tc = type(self.detected_callback) if tc is not list: self.detected_callback = [self.detected_callback] if len(self.detected_callback) == 1 and self.num_hotwords > 1: self.detected_callback *= self.num_hotwords assert self.num_hotwords == len(self.detected_callback), \ "Error: hotwords in your models (%d) do not match the number of " \ "callbacks (%d)" % (self.num_hotwords, len(self.detected_callback)) logger.debug("detecting...") SR = SpeechRecorder() while not self.kill_received: #if not self.paused: if self.interrupt_check(): logger.debug("detect voice break") break data = self.ring_buffer.get() if len(data) == 0: time.sleep(self.sleep_time) continue self.saveMessage( data ) # Save trigger data so it can be append to the record for STT status = self.detector.RunDetection(data) if status > 0: #key word found SR.start() # Start the speech recorder Utils.print_info("Keyword " + self.keyword_names[status] + " detected") Cortex.save( 'kalliope_trigger_called', self.keyword_names[status] ) # I save it to the Cortex, to use it by another neuron # for changing the tts acording to the trigger name HookManager.on_triggered() callback = self.detected_callback[status - 1] if callback is not None: callback() if status == -1: logger.warning( "Error initializing streams or reading audio data") logger.debug("finished.")