Example #1
0
    def start(
        self,
        preload: Optional[bool] = None,
        block: bool = True,
        timeout: float = 60,
        observer: Optional[RhasspyActor] = None,
    ) -> None:
        """Start Rhasspy"""

        if self.actor_system is None:
            self.actor_system = ActorSystem()

        if preload is None:
            preload = self.profile.get("rhasspy.preload_profile", False)

        assert self.actor_system is not None
        self.dialogue_manager = self.actor_system.createActor(DialogueManager)
        with self.actor_system.private() as sys:
            sys.ask(
                self.dialogue_manager,
                ConfigureEvent(
                    self.profile,
                    preload=preload,
                    ready=block,
                    transitions=False,
                    load_timeout_sec=30,
                    observer=observer,
                ),
            )

            # Block until ready
            if block:
                result = sys.listen(timeout)
Example #2
0
    def start(self,
              preload: Optional[bool] = None,
              block: bool = True,
              timeout: float = 60) -> None:
        """Start Rhasspy"""

        if self.actor_system is None:
            kwargs = {}
            if not self.do_logging:
                kwargs["logDefs"] = {"version": 1, "loggers": {"": {}}}

            self.actor_system = ActorSystem("multiprocTCPBase", **kwargs)

        preload = preload or self.profile.get("rhasspy.preload_profile", False)
        assert self.actor_system is not None
        self.dialogue_manager = self.actor_system.createActor(DialogueManager)
        with self.actor_system.private() as sys:
            sys.ask(
                self.dialogue_manager,
                ConfigureEvent(
                    self.profile,
                    preload=preload,
                    ready=block,
                    transitions=False,
                    load_timeout_sec=30,
                ),
            )

            # Block until ready
            if block:
                result = sys.listen(timeout)
Example #3
0
 def get_problems(self) -> Dict[str, Any]:
     """Returns a dictionary with problems from each actor."""
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, GetProblems())
         assert isinstance(result, Problems), result
         return result.problems
Example #4
0
 def transcribe_wav(self, wav_data: bytes) -> WavTranscription:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager,
                          TranscribeWav(wav_data, handle=False))
         assert isinstance(result, WavTranscription)
         return result
Example #5
0
 def record_command(self, timeout: Optional[float] = None) -> VoiceCommand:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager,
                          GetVoiceCommand(timeout=timeout))
         assert isinstance(result, VoiceCommand)
         return result
Example #6
0
 def recognize_intent(self, text: str) -> IntentRecognized:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager,
                          RecognizeIntent(text, handle=False))
         assert isinstance(result, IntentRecognized)
         return result
Example #7
0
 def listen_for_command(self, handle: bool = True) -> Dict[str, Any]:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager,
                          ListenForCommand(handle=handle))
         assert isinstance(result, dict)
         return result
Example #8
0
    def wakeup_and_wait(self) -> Union[WakeWordDetected, WakeWordNotDetected]:
        assert self.actor_system is not None
        with self.actor_system.private() as sys:
            result = sys.ask(self.dialogue_manager, ListenForWakeWord())
            assert isinstance(result, WakeWordDetected) or isinstance(
                result, WakeWordNotDetected)

            return result
Example #9
0
 def get_word_pronunciations(
     self, words: List[str], n: int = 5
 ) -> WordPronunciations:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, GetWordPronunciations(words, n))
         assert isinstance(result, WordPronunciations), result
         return result
Example #10
0
 def train(
     self,
     reload_actors: bool = True
 ) -> Union[ProfileTrainingComplete, ProfileTrainingFailed]:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager,
                          TrainProfile(reload_actors=reload_actors))
         assert isinstance(result, ProfileTrainingComplete) or isinstance(
             result, ProfileTrainingFailed)
         return result
Example #11
0
    def recognize_intent(self, text: str) -> IntentRecognized:
        assert self.actor_system is not None
        with self.actor_system.private() as sys:
            result = sys.ask(self.dialogue_manager, RecognizeIntent(text, handle=False))
            assert isinstance(result, IntentRecognized), result

            # Add slots
            intent_slots = {}
            for ev in result.intent.get("entities", []):
                intent_slots[ev["entity"]] = ev["value"]

            result.intent["slots"] = intent_slots

            return result
Example #12
0
    def recognize_intent(self, text: str) -> IntentRecognized:
        assert self.actor_system is not None
        with self.actor_system.private() as sys:
            # Fix casing
            dict_casing = self.profile.get("speech_to_text.dictionary_casing", "")
            if dict_casing == "lower":
                text = text.lower()
            elif dict_casing == "upper":
                text = text.upper()

            result = sys.ask(self.dialogue_manager, RecognizeIntent(text, handle=False))
            assert isinstance(result, IntentRecognized), result

            # Add slots
            intent_slots = {}
            for ev in result.intent.get("entities", []):
                intent_slots[ev["entity"]] = ev["value"]

            result.intent["slots"] = intent_slots

            return result
Example #13
0
 def get_actor_states(self) -> Dict[str, str]:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, GetActorStates())
         assert isinstance(result, dict)
         return result
Example #14
0
 def speak_sentence(self, sentence: str) -> SentenceSpoken:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, SpeakSentence(sentence))
         assert isinstance(result, SentenceSpoken)
         return result
Example #15
0
 def speak_word(self, word: str) -> WordSpoken:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, SpeakWord(word))
         assert isinstance(result, WordSpoken)
         return result
Example #16
0
 def get_word_phonemes(self, word: str) -> WordPhonemes:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, GetWordPhonemes(word))
         assert isinstance(result, WordPhonemes)
         return result
Example #17
0
 def handle_intent(self, intent: Dict[str, Any]) -> IntentHandled:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, HandleIntent(intent))
         assert isinstance(result, IntentHandled)
         return result
Example #18
0
 def get_speakers(self, system: Optional[str] = None) -> Dict[Any, Any]:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, GetSpeakers(system))
         assert isinstance(result, dict)
         return result
Example #19
0
 def test_microphones(self, system: Optional[str] = None) -> Dict[Any, Any]:
     assert self.actor_system is not None
     with self.actor_system.private() as sys:
         result = sys.ask(self.dialogue_manager, TestMicrophones(system))
         assert isinstance(result, dict)
         return result