Ejemplo n.º 1
0
    def apiai_callback(self, recognizer, audio):
        """
        called from the background thread
        :param recognizer:
        :param audio:
        :return:
        """
        try:
            captured_audio = recognizer.recognize_api(audio,
                                                      client_access_token=self.key,
                                                      language=self.language,
                                                      session_id=self.session_id,
                                                      show_all=self.show_all)
            Utils.print_success("Apiai Speech Recognition thinks you said %s" % captured_audio)
            self._analyse_audio(captured_audio)

        except sr.UnknownValueError as e:
            Utils.print_warning("Apiai Speech Recognition could not understand audio; {0}".format(e))
            # callback anyway, we need to listen again for a new order
            self._analyse_audio(audio_to_text=None)
        except sr.RequestError as e:
            Utils.print_danger("Could not request results from Apiai Speech Recognition service; {0}".format(e))
            # callback anyway, we need to listen again for a new order
            self._analyse_audio(audio_to_text=None)

        # stop listening for an audio
        self.stop_listening()
Ejemplo n.º 2
0
    def google_callback(self, recognizer, audio):
        """
        called from the background thread
        """
        try:
            captured_audio = recognizer.recognize_google(
                audio,
                key=self.key,
                language=self.language,
                show_all=self.show_all)
            Utils.print_success(
                "Google Speech Recognition thinks you said %s" %
                captured_audio)
            self._analyse_audio(audio_to_text=captured_audio)
        except sr.UnknownValueError:
            Utils.print_warning(
                "Google Speech Recognition could not understand audio")
            # callback anyway, we need to listen again for a new order
            self._analyse_audio(audio_to_text=None)
        except sr.RequestError as e:
            Utils.print_danger(
                "Could not request results from Google Speech Recognition service; {0}"
                .format(e))
            # callback anyway, we need to listen again for a new order
            self._analyse_audio(audio_to_text=None)

        self.stop_listening()
Ejemplo n.º 3
0
    def wit_callback(self, recognizer, audio):
        try:
            captured_audio = recognizer.recognize_wit(audio,
                                                      key=self.key,
                                                      show_all=self.show_all)
            Utils.print_success(
                "Wit.ai Speech Recognition thinks you said %s" %
                captured_audio)
            self._analyse_audio(captured_audio)

        except sr.UnknownValueError:
            Utils.print_warning(
                "Wit.ai Speech Recognition could not understand audio")
            # callback anyway, we need to listen again for a new order
            self._analyse_audio(audio_to_text=None)
        except sr.RequestError as e:
            Utils.print_danger(
                "Could not request results from Wit.ai Speech Recognition service; {0}"
                .format(e))
            # callback anyway, we need to listen again for a new order
            self._analyse_audio(audio_to_text=None)

        # stop listening for an audio
        self.stop_listening()
Ejemplo n.º 4
0
def start_intelora(settings, brain):
    """
    Start all signals declared in the brain
    """
    # start intelora
    Utils.print_success("")
    Utils.print_success("Intelora is initializing the agent:")
    time.sleep(randint(1, 3))
    Utils.print_success("Brain................[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Neurons..............[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Synapses.............[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Speech Recognizer....[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Order Manager........[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Speech Synthesizer...[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Triggers.............[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("Variables............[OK]")
    time.sleep(randint(1, 3))
    Utils.print_success("")
    Utils.print_success("Agent is now online!")
    Utils.print_success("")
    Utils.print_info("Press Ctrl+C to stop Intelora")
    # catch signal for killing on Ctrl+C pressed
    signal.signal(signal.SIGINT, signal_handler)

    # get a list of signal class to load from declared synapse in the brain
    # this list will contain string of signal class type.
    # For example, if the brain contains multiple time the signal type "order", the list will be ["order"]
    # If the brain contains some synapse with "order" and "event", the list will be ["order", "event"]
    list_signals_class_to_load = get_list_signal_class_to_load(brain)

    # start each class name

    for signal_class_name in list_signals_class_to_load:
        signal_instance = SignalLauncher.launch_signal_class_by_name(
            signal_name=signal_class_name, settings=settings)
        if signal_instance is not None:
            signal_instance.daemon = True
            signal_instance.start()

    while True:  # keep main thread alive
        time.sleep(0.1)