Beispiel #1
0
    def handle_forward(self, message: Any, sender: RhasspyActor) -> None:
        """Forward messages to appropriate actor."""
        if isinstance(message, GetMicrophones):
            # Get all microphones
            recorder_class = self.recorder_class
            if message.system is not None:
                recorder_class = get_microphone_class(message.system)

            try:
                assert recorder_class is not None
                mics = recorder_class.get_microphones()
            except Exception:
                self._logger.exception("get_microphones")
                mics = {}

            self.send(sender, mics)
        elif isinstance(message, TestMicrophones):
            # Get working microphones
            recorder_system = self.profile.get("microphone.system", "pyaudio")
            if message.system is not None:
                recorder_system = message.system

            recorder_class = get_microphone_class(recorder_system)
            test_path = f"microphone.{recorder_system}.test_chunk_size"
            chunk_size = int(self.profile.get(test_path, 1024))

            assert recorder_class is not None
            test_mics = recorder_class.test_microphones(
                chunk_size)  # type: ignore
            self.send(sender, test_mics)
        elif isinstance(message, GetSpeakers):
            # Get all speakers
            player_class = self.player_class
            if message.system is not None:
                player_class = get_sound_class(message.system)

            assert player_class is not None
            speakers = player_class.get_speakers()
            self.send(sender, speakers)
        elif isinstance(message, (PlayWavData, PlayWavFile)):
            # Forward to audio player
            self.send(self.player, message)
        elif isinstance(message, MqttPublish):
            # Forward directly
            if self.mqtt is not None:
                self.send(self.mqtt, message)
        elif isinstance(message, AudioData):
            # Forward to audio recorder
            self.send(self.recorder, message)
        elif not isinstance(message, (StateTransition, ChildActorExited)):
            self._logger.warning("Unhandled message: %s", message)
Beispiel #2
0
    def load_actors(self) -> None:
        """Load all system actors."""
        self._logger.debug("Loading actors")

        # Microphone
        mic_system = self.profile.get("microphone.system", "dummy")
        self.recorder_class = get_microphone_class(mic_system)
        self._recorder = self.createActor(self.recorder_class)
        self.actors["recorder"] = self.recorder

        # Audio player
        player_system = self.profile.get("sounds.system", "dummy")
        self.player_class = get_sound_class(player_system)
        self._player = self.createActor(self.player_class)
        self.actors["player"] = self.player

        # Text to Speech
        speech_system = self.profile.get("text_to_speech.system", "dummy")
        self.speech_class = get_speech_class(speech_system)
        self._speech = self.createActor(self.speech_class)
        self.actors["speech"] = self.speech

        # Wake listener
        wake_system = self.profile.get("wake.system", "dummy")
        self.wake_class = get_wake_class(wake_system)
        self._wake = self.createActor(self.wake_class)
        self.actors["wake"] = self.wake

        # Command listener
        command_system = self.profile.get("command.system", "dummy")
        self.command_class = get_command_class(command_system)
        self._command = self.createActor(self.command_class)
        self.actors["command"] = self.command

        # Speech decoder
        decoder_system = self.profile.get("speech_to_text.system", "dummy")
        self.decoder_class = get_decoder_class(decoder_system)
        self._decoder = self.createActor(self.decoder_class)
        self.actors["decoder"] = self.decoder

        # Intent recognizer
        recognizer_system = self.profile.get("intent.system", "dummy")
        self.recognizer_class = get_recognizer_class(recognizer_system)
        self._recognizer = self.createActor(self.recognizer_class)
        self.actors["recognizer"] = self.recognizer

        # Intent handler
        handler_system = self.profile.get("handle.system", "dummy")
        self.handler_class = get_intent_handler_class(handler_system)
        self._handler = self.createActor(self.handler_class)
        self.actors["handler"] = self.handler

        self.hass_handler = None
        forward_to_hass = self.profile.get("handle.forward_to_hass", False)
        if (handler_system != "hass") and forward_to_hass:
            # Create a separate actor just for home assistant
            from rhasspy.intent_handler import HomeAssistantIntentHandler

            self.hass_handler = self.createActor(HomeAssistantIntentHandler)
            self.actors["hass_handler"] = self.hass_handler

        # Speech trainer
        speech_trainer_system = self.profile.get(
            "training.speech_to_text.system", "auto")
        self.speech_trainer_class = get_speech_trainer_class(
            speech_trainer_system, decoder_system)

        self._speech_trainer = self.createActor(self.speech_trainer_class)
        self.actors["speech_trainer"] = self.speech_trainer

        # Intent trainer
        intent_trainer_system = self.profile.get("training.intent.system",
                                                 "auto")
        self.intent_trainer_class = get_intent_trainer_class(
            intent_trainer_system, recognizer_system)

        self._intent_trainer = self.createActor(self.intent_trainer_class)
        self.actors["intent_trainer"] = self.intent_trainer

        # Word pronouncer
        from rhasspy.pronounce import PhonetisaurusPronounce

        self.word_pronouncer_class = PhonetisaurusPronounce
        self._word_pronouncer = self.createActor(self.word_pronouncer_class)
        self.actors["word_pronouncer"] = self.word_pronouncer

        # Configure actors
        self.wait_actors = {}
        for name, actor in self.actors.items():
            if (actor is None) or (actor == self.mqtt):
                continue  # skip

            self.send(
                actor,
                ConfigureEvent(self.profile,
                               preload=self.preload,
                               **self.actors))
            self.wait_actors[name] = actor

        actor_names = list(self.wait_actors.keys())
        self._logger.debug("Actors created. Waiting for %s to start.",
                           actor_names)