コード例 #1
0
    def in_started(self, message: Any, sender: RhasspyActor) -> None:
        """Handle messages in started state."""
        if isinstance(message, ListenForCommand):
            self.buffer = bytes()
            self.receiver = message.receiver or sender
            self.handle = message.handle
            self.transition("listening")

            if message.timeout is not None:
                # Use message timeout
                timeout_sec = message.timeout
            else:
                # Use default timeout
                timeout_sec = self.timeout_sec

            self.send(self.recorder, StartStreaming(self.myAddress))
            self.timeout_id = str(uuid.uuid4())
            self.wakeupAfter(timedelta(seconds=timeout_sec), payload=self.timeout_id)
        elif isinstance(message, MqttMessage):
            # startListening
            if message.topic == self.start_topic:
                payload_json = json.loads(message.payload)
                if payload_json.get("siteId", "default") in self.site_ids:
                    # Wake up Rhasspy
                    self._logger.debug("Received startListening")
                    self.send(self._parent, ListenForCommand())
コード例 #2
0
ファイル: dialogue.py プロジェクト: saonam/rhasspy
    def to_awake(self, from_state: str) -> None:
        """Transition to awake state."""
        self.send(self.wake, StopListeningForWakeWord())

        # Wake up beep
        wav_path = os.path.expandvars(self.profile.get("sounds.wake", None))
        if wav_path is not None:
            self.send(self.player, PlayWavFile(wav_path))

        # Listen for a voice command
        self.send(
            self.command,
            ListenForCommand(
                self.myAddress, handle=self.handle, timeout=self.listen_timeout_sec
            ),
        )
コード例 #3
0
    async def listen_for_command(
        self,
        handle: bool = True,
        timeout: Optional[float] = None,
        entity: Optional[str] = None,
        value: Optional[str] = None,
    ) -> Dict[str, Any]:
        """Block until a voice command has been spoken. Optionally handle it."""
        assert self.actor_system is not None
        with self.actor_system.private() as sys:
            entities = None
            if entity is not None:
                entities = [{"entity": entity, "value": value}]

            result = await sys.async_ask(
                self.dialogue_manager,
                ListenForCommand(handle=handle,
                                 timeout=timeout,
                                 entities=entities),
            )
            assert isinstance(result, dict), result

            return result
コード例 #4
0
ファイル: dialogue.py プロジェクト: saonam/rhasspy
    def handle_any(self, message: Any, sender: RhasspyActor) -> None:
        """Handle messages in any state."""
        if isinstance(message, ListenForCommand):
            # Force voice command
            self.handle = message.handle
            self.intent_receiver = message.receiver or sender
            self.listen_timeout_sec = message.timeout
            self.listen_entities = message.entities
            self.transition("awake")
        elif isinstance(message, GetVoiceCommand):
            # Record voice command, but don't do anything with it
            self.send(
                self.command,
                ListenForCommand(message.receiver or sender, timeout=message.timeout),
            )
        elif isinstance(message, TranscribeWav):
            # speech -> text
            self.send(
                self.decoder,
                TranscribeWav(message.wav_data, sender, handle=message.handle),
            )
        elif isinstance(message, RecognizeIntent):
            # text -> intent
            self.send(
                self.recognizer,
                RecognizeIntent(
                    message.text,
                    confidence=message.confidence,
                    receiver=sender,
                    handle=message.handle,
                ),
            )
        elif isinstance(message, HandleIntent):
            # intent -> action
            self.send(self.handler, HandleIntent(message.intent, sender))

            # Forward to MQTT (hermes)
            if self.mqtt is not None:
                self.send(self.mqtt, IntentRecognized(message.intent))
        elif isinstance(message, GetWordPhonemes):
            # eSpeak -> CMU
            self.send(
                self.word_pronouncer, GetWordPhonemes(message.word, receiver=sender)
            )
        elif isinstance(message, SpeakWord):
            # eSpeak -> WAV
            self.send(self.word_pronouncer, SpeakWord(message.word, receiver=sender))
        elif isinstance(message, GetWordPronunciations):
            # word -> [CMU]
            self.send(
                self.word_pronouncer,
                GetWordPronunciations(message.words, n=message.n, receiver=sender),
            )
        elif isinstance(message, SpeakSentence):
            # text -> speech
            self.send(
                self.speech,
                SpeakSentence(
                    message.sentence,
                    receiver=sender,
                    play=message.play,
                    voice=message.voice,
                    language=message.language,
                ),
            )
        elif isinstance(message, TrainProfile):
            # Training
            self.reload_actors_after_training = message.reload_actors
            self.send(self.wake, StopListeningForWakeWord())
            self.training_receiver = message.receiver or sender
            self.transition("training_sentences")
            # self.send(self.sentence_generator, GenerateSentences())
        elif isinstance(message, StartRecordingToBuffer):
            # Record WAV
            self.send(self.recorder, message)
        elif isinstance(message, StopRecordingToBuffer):
            # Stop recording WAV
            self.send(
                self.recorder,
                StopRecordingToBuffer(message.buffer_name, message.receiver or sender),
            )
        elif isinstance(message, StateTransition):
            # Track state of every actor
            self.handle_transition(message, sender)
        elif isinstance(message, GetActorStates):
            self.send(sender, self.actor_states)
        elif isinstance(message, WakeupMessage):
            pass
        elif isinstance(message, WavPlayed):
            pass
        elif isinstance(message, GetProblems):
            # Report problems from child actors
            self.send(sender, Problems(self.problems))
        else:
            self.handle_forward(message, sender)